colormap option does not work with imshow in MATLAB 2017a
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Vishwa Parekh
le 27 Mar 2017
Commenté : QQ Tong
le 31 Oct 2017
colormap option does not work with imshow in MATLAB 2017a.
0 commentaires
Réponse acceptée
Andrew Gilman
le 23 Juin 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 commentaires
Plus de réponses (1)
Jyotish Robin
le 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:
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:
So, hopefully you could update the code as above to get the desired behaviour.
Hope this answer helps!
Regards,
Jyotish
1 commentaire
Voir également
Catégories
En savoir plus sur Red dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!