Clear Filters
Clear Filters

How to make an axis two different plots the same using the aspect ratio and how to set the contour colors the same.

7 views (last 30 days)
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.

Answers (1)

Balavignesh
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

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!