How to make the colorbar/colormap with colors the same as ANSYS in Matlab?

10 vues (au cours des 30 derniers jours)
In ANSYS, when there is zero deflection, the color is blue. For maximum negative and maximum positive, red is shown. In matlab, when there is zero deflection, the color is green. For maximum positive deflection the color is red and for maximum negative deflection the color is blue. How to configure Matlab to display the same colorbar as Ansys?
See the difference between the figures:
Matlab:
Ansys:
Thank you!

Réponse acceptée

William Rose
William Rose le 28 Mai 2024
Modifié(e) : William Rose le 28 Mai 2024
[edit: Fix spelling errors in my remarks. No changes to the code.]
x=0:.01:6; y=0:.01:2;
[X,Y]=meshgrid(x,y);
Z=sin(pi*X/2).*sin(pi*Y/2);
% plot results
figure
surf(X,Y,Z,EdgeColor="none");
axis equal; grid on; colorbar
xlabel('X'); ylabel('Y'); zlabel('Z')
%make custom color map
hue=[0:.01:.67,.66:-.01:0]';
nc=length(hue);
colors=hsv2rgb([hue,ones(nc,2)]);
colormap(colors)
The key is to recognize that progression from red through green to blue corresponds to hue=0 (red), hue=0.333 (green), hue=0.667 (blue). Then you want to go backwards, from blue to green to red. Therefore you can create a hue vector which goes in steps from 0 to 0.67, then back to 0. Then convert the hue vector to RGB colors, since the colormap() function wants a set of RGB colors. When converting the hue vector to RGB colors with hsv2rgb(), use a column of ones for the saturations and a column of ones for the values (S and V in "HSV").
  3 commentaires
Lidianne Mapa
Lidianne Mapa le 28 Mai 2024
Thank you very much!
William Rose
William Rose le 29 Mai 2024
@Lidianne Mapa, you're welcome.
@Mario Malic, Ansys is plotting negative as well as positive deflections on the z-axis. But the label on the Ansys colorbar only shows the magnitude, or, equivalently, it only shows deflection values from 0 to 1. I don't know how to make Matlab do this.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by