Use two colormaps on 3D figure.

5 ビュー (過去 30 日間)
Santos García Rosado
Santos García Rosado 2021 年 4 月 13 日
コメント済み: Adam Danz 2021 年 4 月 14 日
Hello Mathwork's community!
I've used the surf function in order to get the attached figure.
I was wondering if I could use two different colormaps so that when z<= 10 I could use for example colormap winter. And when z>10 use colormap summer.
Any ideas on how I can achieve this succesfully?
Thank's in advance for your time.
Santos

採用された回答

Adam Danz
Adam Danz 2021 年 4 月 14 日
Follow this demo. The colorbar ranges approximately from -6 to 8 and the transition between Winter and Summer colormaps happens at 2.
Key variables
  • h - handle to the surface object
  • transitionValue - the color value where the transition should happen
  • n - the total number of values in the combined colormap (the more the better).
  • ax - the axis handle.
[X,Y,Z] = peaks(25);
h = surf(X,Y,Z);
axis square
colorbar
% set transition value
transitionValue = 2;
n = 256; % number of colormap value
ax = gca();
% change colormap. Use winter below transition value
% and summer above transition value.
clim = [min(h.CData(:)), max(h.CData(:))]; % range of color values
np = round(abs(clim - transitionValue) / range(clim) * n); %number of color values from each colormap
cmap = [winter(np(1)); summer(np(2))];
ax.Colormap = cmap;
ax.CLim = clim;
  2 件のコメント
Santos García Rosado
Santos García Rosado 2021 年 4 月 14 日
編集済み: Santos García Rosado 2021 年 4 月 14 日
Thank you Adam! I just adjusted your demo to my code and is working great!
Adam Danz
Adam Danz 2021 年 4 月 14 日
Great to hear!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBlue についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by