Require Surface Plot Color Bar Consistant across multiple plots.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (1)
nick
el 16 de Abr. de 2025
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
0 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!