How to make colorbars symmetric?

조회 수: 28 (최근 30일)
Dirk
Dirk 2013년 6월 3일
답변: Walter Roberson 2023년 6월 1일
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