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

12 views (last 30 days)
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!

Accepted Answer

William Rose
William Rose on 28 May 2024
Edited: William Rose on 28 May 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 Comments
William Rose
William Rose on 29 May 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!