Require Surface Plot Color Bar Consistant across multiple plots.

조회 수: 2 (최근 30일)
Jaye
Jaye 2012년 1월 31일
답변: nick 2025년 4월 16일
I am plotting various different plots
figure
a=[-1 1 -1 -2; 1 2 3 4; 1 1 1 1; -2 -3 -4 -5; -4 -5 -6 -8]
surf([1 2 3 4],[1 2 3 4 5],a)
colorbar
figure
b=[-2 2 -2 -4; 2 4 6 8; 2 2 2 2; -4 -6 -8 -10; -8 -10 -8 -16]
surf([1 2 3 4],[1 2 3 4 5],b)
colorbar
And I want the colorbars to be consistant to enable easy comparison as to relative extreme values. I want the color representing -8 on one graph to be same color as -8 on the other graph. Is this possible?

답변 (1개)

nick
nick 2025년 4월 16일
Hello Jaye,
To achieve this, you need to set the color limits 'caxis' for both plots to be the same, as shown:
% Data for the first plot
a = [-1 1 -1 -2; 1 2 3 4; 1 1 1 1; -2 -3 -4 -5; -4 -5 -6 -8];
% Data for the second plot
b = [-2 2 -2 -4; 2 4 6 8; 2 2 2 2; -4 -6 -8 -10; -8 -10 -8 -16];
% Determine the global minimum and maximum values across both datasets
global_min = min(min([a(:); b(:)]));
global_max = max(max([a(:); b(:)]));
% Plot the first surface
figure;
surf([1 2 3 4], [1 2 3 4 5], a);
colorbar;
caxis([global_min global_max]); % Set consistent color limits
% Plot the second surface
figure;
surf([1 2 3 4], [1 2 3 4 5], b);
colorbar;
caxis([global_min global_max]); % Set consistent color limits
Kindly refer to the documentation by executing the following command in MATLAB Command Window to know more about 'caxis' function :
doc caxis

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by