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

조회 수: 3 (최근 30일)
University 2024년 2월 6일
답변: Balavignesh 2024년 2월 11일
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.

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Balavignesh 2024년 2월 11일
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

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by