colormap option does not work with imshow in MATLAB 2017a

5 ビュー (過去 30 日間)
Vishwa Parekh
Vishwa Parekh 2017 年 3 月 27 日
コメント済み: QQ Tong 2017 年 10 月 31 日
colormap option does not work with imshow in MATLAB 2017a.

採用された回答

Andrew Gilman
Andrew Gilman 2017 年 6 月 23 日
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.

その他の回答 (1 件)

Jyotish Robin
Jyotish Robin 2017 年 3 月 30 日
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 件のコメント
QQ Tong
QQ Tong 2017 年 10 月 31 日
Thank you very muuuuuch! Already solved my problem!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRed についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by