colormap option does not work with imshow in MATLAB 2017a
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Vishwa Parekh
il 27 Mar 2017
Commentato: QQ Tong
il 31 Ott 2017
colormap option does not work with imshow in MATLAB 2017a.
0 Commenti
Risposta accettata
Andrew Gilman
il 23 Giu 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 Commenti
Più risposte (1)
Jyotish Robin
il 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 Commento
Vedere anche
Categorie
Scopri di più su Red in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!