# How to set custom colormap in MATLAB

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

Categories: Computing