colormap option does not work with imshow in MATLAB 2017a
4 views (last 30 days)
Show older comments
colormap option does not work with imshow in MATLAB 2017a.
0 Comments
Accepted Answer
Andrew Gilman
on 23 Jun 2017
It looks like imshow() now sets the axis colormap (it uses default if colormap is not specified). Axis colormap over-rides the figure colormap - this allows to have multiple axis with different colormaps.
colormap function sets figure's colormap by default when no handle is specified, but this is over-ridden by the axis colormap and you don't see any change.
To change the colormap you can use colormap(gca,jet), which will set colormap to the axis. Alternatively use image() instead of imshow(), which doesn't seem to set axis colormap and changing the figure colormap with the usual colormap jet has an effect on the image.
0 Comments
More Answers (1)
Jyotish Robin
on 30 Mar 2017
Hi!
Since you haven't provided much detail on how you are using 'imshow' and 'colormap' functions, I am writing a sample code to illustrate the issue and hopefully this matches with your usecase:
map = [0.83, 0.83, 0.83
0.7, 0.7, 0
0.1, 0.5, 0.8
0.2, 0.7, 0.6
1, 0, 0
];
figure;
subplot(1,2,1); imshow(peaks), title('Image 1');
colormap(map); colorbar
subplot(1,2,2); imshow(peaks), title('Image 2');
colormap(map); colorbar
The output figure is something like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173601/image.png)
If you read the documentation, it says that 'imshow' can be used in conjunction with 'subplot' to create figures with multiple images, even if the images have different colormaps. If a colormap is specified, 'imshow' uses the 'colormap' function to change the colormap of the axes containing the displayed image. In R2016a and prior releases, imshow changed the Colormap property of the figure containing the image.
Now if you rewrite the code as
map = [0.83, 0.83, 0.83
0.7, 0.7, 0
0.1, 0.5, 0.8
0.2, 0.7, 0.6
1, 0, 0
];
figure;
subplot(1,2,1); imshow(peaks, map), title('Image 1');
colorbar
subplot(1,2,2); imshow(peaks, map), title('Image 2');
colorbar
You get the following figure as output:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173603/image.png)
So, hopefully you could update the code as above to get the desired behaviour.
Hope this answer helps!
Regards,
Jyotish
1 Comment
See Also
Categories
Find more on Red in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!