- 'axis' function: https://www.mathworks.com/help/matlab/ref/axis.html
- 'colormap' function: https://www.mathworks.com/help/matlab/ref/colormap.html
- 'subplots': https://www.mathworks.com/help/matlab/ref/subplot.html
How to make an axis two different plots the same using the aspect ratio and how to set the contour colors the same.
6 views (last 30 days)
Show older comments
How to make an axis these two different plots the same using the aspect ratio and how to set the contour colors the same? Although my code is not here, an example will help.
0 Comments
Answers (1)
Balavignesh
on 11 Feb 2024
Hi,
As per my understanding, you would like to ensure the different plots in MATLAB have the same aspect ratio and contour colors.
I would suggest you use the 'axis' function to set the aspect ration and 'colormap' function to synhronize the colors across plots. Below is an example code snippet that could help you understand this:
% Generate some sample data for the plots
[x, y] = meshgrid(linspace(-3, 3, 100), linspace(-3, 3, 100));
z1 = x.^2 + y.^2;
z2 = sin(x) + cos(y);
% Create the first plot
subplot(1, 2, 1);
contourf(x, y, z1, 20); % 20 contour levels
title('Plot 1');
xlabel('X-axis');
ylabel('Y-axis');
axis equal; % Set aspect ratio to be equal
colorbar;
% Create the second plot
subplot(1, 2, 2);
contourf(x, y, z2, 20); % 20 contour levels to match the first plot
title('Plot 2');
xlabel('X-axis');
ylabel('Y-axis');
axis equal; % Set aspect ratio to be equal
colorbar;
% Set the same colormap for both plots
colormap('jet'); % You can choose any colormap you prefer (e.g., 'jet', 'hsv', 'hot', etc.)
% If you want to synchronize the color limits (color scales) as well, you can do the following:
clims = [min([z1(:); z2(:)]), max([z1(:); z2(:)])]; % Find common color limits
subplot(1, 2, 1);
caxis(clims); % Set color limits for the first plot
subplot(1, 2, 2);
caxis(clims); % Set color limits for the second plot
Kindly have a look at the following documentation links to have more understanding on:
Hope that helps!
Balavignesh
0 Comments
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!