フィルターのクリア

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

29 ビュー (過去 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 Center および File ExchangeColormaps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by