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

11 次查看(过去 30 天)
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!

采纳的回答

William Rose
William Rose 2024-5-28
编辑:William Rose 2024-5-28
[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 个评论
William Rose
William Rose 2024-5-29
@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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by