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

조회 수: 30 (최근 30일)
Peter Fraser
Peter Fraser 2017년 2월 22일
댓글: Peter Fraser 2017년 2월 25일
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)?
Thanks
Pete

채택된 답변

Michael Abboud
Michael Abboud 2017년 2월 24일
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;
figure;
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:
  댓글 수: 2
Steven Lord
Steven Lord 2017년 2월 24일
You probably also want to use linkprop to keep the axes limits and color axis limits (the CLim and CLimMode properties, as mentioned on the documentation page for caxis) synchronized if one or both of the axes changes after you've set their limits initially.
Peter Fraser
Peter Fraser 2017년 2월 25일
Perfect. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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