How to use different colormaps for different function in mesh plot.

3 ビュー (過去 30 日間)
U B
U B 2024 年 9 月 5 日
編集済み: Voss 2024 年 9 月 5 日
Using different colormaps for same axis is not logical but if I want want to somehow do it then what should I do?
x = linspace(-3,3,100); y = linspace(0,3,100);
[X,Y] = meshgrid(x,y);
Rho2 = X.*X + Y.*Y;
Z = exp(-Rho2);
Z1 = sin(sqrt(Rho2));
figure,
mesh(X,Y,Z,'FaceAlpha',1); hold on
mesh(X,Y,Z1,'FaceAlpha',1);
I'm using R2021a and freezColors function is not suporting, it shows error. Perhaps I'm using it wrong. Anybody has any idea how to do it?
Appriciate your help.
  1 件のコメント
Walter Roberson
Walter Roberson 2024 年 9 月 5 日
You need to install it to use it (possibly use the Add-On Explorer to install it)

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

採用された回答

Voss
Voss 2024 年 9 月 5 日
編集済み: Voss 2024 年 9 月 5 日
Here is one way:
% data
x = linspace(-3,3,100); y = linspace(0,3,100);
[X,Y] = meshgrid(x,y);
Rho2 = X.*X + Y.*Y;
Z = exp(-Rho2);
Z1 = sin(sqrt(Rho2));
% pick some colormaps
cmap = parula();
cmap1 = turbo();
% convert Z and Z1 into colors based on their respective colormaps
C = ind2rgb(round(rescale(Z,1,size(cmap,1))),cmap);
C1 = ind2rgb(round(rescale(Z1,1,size(cmap1,1))),cmap1);
% plot the meshes
figure
mesh(X,Y,Z,C,'FaceAlpha',1); hold on
mesh(X,Y,Z1,C1,'FaceAlpha',1);
  4 件のコメント
U B
U B 2024 年 9 月 5 日
Sorry to disturb you again but can I use the same method in contour plot also?
lets say for -
contourf(X,Y,Z,70,'edgecolor','none') ; hold on
contourf(X,Y,Z1,70,'edgecolor','none'); hold off
Voss
Voss 2024 年 9 月 5 日
編集済み: Voss 2024 年 9 月 5 日
No, I don't think so.
The options listed here for countour plots
basically boil down to 1) a constant color everywhere, or 2) using the current colormap. Since an axes can have only one colormap, you'd have to use the same colormap for all contour plots in a given axes. There doesn't appear to be a way to specify an array of RGB colors for a contour like you can for a surface/mesh.

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

その他の回答 (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