Require Surface Plot Color Bar Consistant across multiple plots.
古いコメントを表示
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 件)
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
カテゴリ
ヘルプ センター および File Exchange で Surface and Mesh Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

