Effacer les filtres
Effacer les filtres

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

26 vues (au cours des 30 derniers jours)
Peter Fraser
Peter Fraser le 22 Fév 2017
Commenté : Peter Fraser le 25 Fév 2017
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

Réponse acceptée

Michael Abboud
Michael Abboud le 24 Fév 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;
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 commentaires
Steven Lord
Steven Lord le 24 Fév 2017
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 le 25 Fév 2017
Perfect. Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by