How to set custom colormap in MATLAB
- Post by: Abhinav Gupta
- March 15, 2019
- No Comment
When we create a surface plot based on X, Y and Z matrices in Matlab using the surf function, it sets the colormap based on the Z matrix. If we want custom colormap based on some other matrix we can do that by specifying the CData property of the surface. To create the same results in Python check this post.
x=[0:0.1:pi];
y=[0:0.1:pi];
[XX,YY]=meshgrid(x,y);
ZZ = sin(XX).*sin(YY);
%We can directly specify the colormap here or else we can call the CData
%property of surface and then set it.
color_map=XX;
s=surf(XX,YY,ZZ,color_map);
s.CData=YY;
References
- How-surface-plot-data-relates-to-a-colormap
- How-to-get-a-surface-handle
- How-can-i-extract-surface-plot-data-from-matlab-figure
- Colorbar
- Caxis
- How-to-remove-axis-from-a-figure
Categories: Computing