Today I was making filled contour plot in Matlab in which the majority of the space is flat and at values close to zero. For the majority of Matlab’s built in colormap
‘s values that are small are given a dark colour e.g. for the default colormap
it’s dark blue, or for the gray
colormap
it’s black. I wanted to invert this so that the small values are lighter, or white and the large values are dark. I’m sure there are other ways to do this (like defining my own colormap
), but here’s what I did to essentially invert the colormap:
>> % make your plot:
>> contourf(data);
>> % select the colormap you wish to invert:
>> colormap gray;
>> % get the matrix containing that colormap:
>> cmap = colormap;
>> % flip the matrix:
>> cmap = flipud(cmap);
>> % apply the new inverted colormap:
>> colormap(cmap);
Below is an example of what this looks like. This plot:
becomes this plot:
Thank you so much! This saved my LIFE.
–Pierce
Cheers! You have helped me to no end!
OMG! you’ve just saved my phd!
Excellent…
Awesome! Thanks
simple and efficient way of doing what I needed. Thanks!