Saving heatmaps as image

32 ビュー (過去 30 日間)
meghna roy chowdhury
meghna roy chowdhury 2020 年 6 月 24 日
コメント済み: Ameer Hamza 2020 年 6 月 25 日
I want to save 3 images as jpg of dimension 227x227-
  1. Heatmap1
  2. Heatmap2
  3. Subplot of Heatmap1 and Heatmap2
This is the code for my heatmaps:
% Heatmap1
subplot(2,1,1)
heata=heatmap(n2E);
heata.GridVisible='off';
colormap(jet)
heata.ColorbarVisible='off';
caxis([-0.4440 0.8660 ])
heata.FontColor='none';
%Heatmap2
subplot(2,1,2)
heatp=heatmap(n2);
heatp.GridVisible='off';
colormap(jet)
heatp.ColorbarVisible='off';
caxis([0 4095])
heatp.FontColor='none';
%subplot of heatmaps
ha=get(gcf,'children');
set(ha(1),'position',[.1 .1 .8 .4])
set(ha(2),'position',[.1 .5 .8 .5])
I was able to save the subplot of the heatmaps using:
Path=strcat('C:\Users\Admin\Documents\MATLAB\h3.jpg';
saveas(gcf,Path);
I'm not able to save Heatmap1 and heatmap2 as seperate image files as well.
Please help me out with the code.

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 6 月 24 日
If you are using R2020a, you can use exportgraphics() ans specify the handle of graphic object.
n2E = rand(10); % for example
n2 = rand(10);
% Heatmap1
subplot(2,1,1)
heata=heatmap(n2E);
heata.GridVisible='off';
colormap(jet)
heata.ColorbarVisible='off';
caxis([-0.4440 0.8660 ])
heata.FontColor='none';
%Heatmap2
subplot(2,1,2)
heatp=heatmap(n2);
heatp.GridVisible='off';
colormap(jet)
heatp.ColorbarVisible='off';
caxis([0 4095])
heatp.FontColor='none';
%subplot of heatmaps
ha=get(gcf,'children');
set(ha(1),'position',[.1 .1 .8 .4])
set(ha(2),'position',[.1 .5 .8 .5])
exportgraphics(gcf, 'figure.jpg');
exportgraphics(ha(1), 'subplot1.jpg');
exportgraphics(ha(2), 'subplot2.jpg');
  2 件のコメント
meghna roy chowdhury
meghna roy chowdhury 2020 年 6 月 24 日
編集済み: meghna roy chowdhury 2020 年 6 月 24 日
Thank you!
I want to save the 2 subplots as 227x227 size images. How do I do that?
Ameer Hamza
Ameer Hamza 2020 年 6 月 25 日
In that case, you may need to read the images, use imresize() and then save the image using imwrite().
img1 = imread('subplot1.jpg');
img1 = imresize(img1, [227, 227]);
imwrite(img1, 'subplot1.jpg');
% same for subplot2
Add these lines at the end of the code.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by