I want surf's colormap range to be determined by the Z axis

35 views (last 30 days)
I am developing code to display two animated side-by-side pressure maps. The pressure maps are 16 x 16 (interpolated to 76 x 76) and are displayed using "surf" repeatedly, as I loop through the frames.
I have allowed two options in the UI. With the independent axes option, the Z axis of each display runs from 0 to 1.1 * the maximum pressure of any element of any frame in that data set. With the linked axes option, I use the maximum value of either data set to set the z axis extents for both data sets. My intention was to have the independent mode fill both data spaces to the maximum, whereas the linked mode allows me to compare like with like.
The color mapping doesn't behave as I expected in linked mode though. The color map range seems to depend on the data range, and not on the Z axis range. This means that the same pressure appears as different colors on the two linked axes displays.
How do I fix this (have the color map range determined by the axes range)?

Accepted Answer

Michael Abboud
Michael Abboud on 24 Feb 2017
You can accomplish the workflow you describe using the "caxis" function, which allows you to set the mapping between your data and your colormap. For example, you could try something similar to the following;
Z = peaks;
hAx1 = subplot(121); surf( peaks); colorbar;
hAx2 = subplot(122); surf(2*peaks); colorbar;
% set z-axes to be equal
ZLim = hAx2.ZLim;
hAx1.ZLim = ZLim;
% scale the colorbar as desired
caxis(hAx1, [ZLim(1), 1.1*ZLim(2)]);
caxis(hAx2, [ZLim(1), 1.1*ZLim(2)]);
For more information, you can refer to the documentation for "caxis" below:

Sign in to comment.

More Answers (0)


Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!