How to make colorbars symmetric?

28 次查看(过去 30 天)
Dirk
Dirk 2013-6-3
Hi
I've following problem;
I've two colorplots with tension values on a surface. Is there a possibility to make the colorbars symmetric?...with i.e. the green color on point 0 but with a different range i.e [-2000 1000] for the left and [-10000 0] for the right plot. So the scale should be the same.
Thanks in advance!

回答(2 个)

Scott Hottovy
Scott Hottovy 2023-6-1
You can grab the max data and center it using the following:
% Plot the data (for example using pcolor)
pcolor(data)
% Get color axis limits
caxis_limits = caxis;
% Adjust color axis limits
max_limit = max(abs(caxis_limits));
caxis([-max_limit max_limit]);
% Add colorbar
colorbar
  1 个评论
Walter Roberson
Walter Roberson 2023-6-1
side note:
Relatively recently, R2022a, MATLAB started to prefer clim instead of caxis()

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2023-6-1
In order to have the color scale be consistent between the two, the axes CLim property must be the same for the two plots. In particular you would want min() of all of the data combined, to max() of all of the data combined as your axes CLim for both axes. You can use the clim convenience function or set the axes CLim property to establish the bounds.
Having done that, it is not necessary that the color bars show the same range. You can record the handles of the colorbar() objects, and you can set the Limits property of the colorbar object. The Limits property determines the portion of the color axes that is drawn in the colorbar, but does not affect the color scaling of the graphics objects.
combined_data = [delta_2_top(:); delta_3_top(:)];
minten = min(combined_data);
maxten = max(combined_data);
subplot(1,2,1);
pcolor(X, Y, delta_2_top);
clim([minten, maxten]);
cb1 = colorbar();
cb1.Limits = [min(delta_2_top), max(delta_2_top)];
subplot(1,2,2);
pcolor(X, Y, delta_3_top);
clim([minten, maxten]);
cb2 = colorbar();
cb2.Limits = [min(delta_3_top), max(delta_3_top)];
The green 0 point would occur roughly 2/3 of the way through for the first plot, and would occur at the right side for the second plot.

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by