Hi,
I plotting the contour with imagesc(), I am saving the final images in .fig and .bmp format. In the .bmp format some portion of the image is cropped, for e.g. colorbar legend got cropped. (please see the attachment). Do I need to reduce the image size.. ???

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 16 日
編集済み: Ameer Hamza 2020 年 10 月 16 日

0 投票

The problem is that the font size of axes labels is quite large, going beyond the figure limits. An easy fix is to change the size of the figure so that all the text is visible (preferrable maximize the figure window) and then run this line.
exportgraphics(gcf, 'file.png', 'Resolution', 300);

7 件のコメント

Turbulence Analysis
Turbulence Analysis 2020 年 10 月 16 日
Hi, Thanks for you reply.
Actually I ruuning the code in for loop, for each iteration i will get one image, hence, my save command is as follows .
Is it possible to implement the above here...?
saveas(gcf, sprintf('VMode%d', k),'bmp')
savefig(gcf, sprintf('VMode%d', k))
Ameer Hamza
Ameer Hamza 2020 年 10 月 16 日
編集済み: Ameer Hamza 2020 年 10 月 16 日
If you are running for-loop then you can do something like this.
Save the two lines in your code with
fig = gcf;
fig.WindowState = 'maximized';
pause(2); % pause for some time to let the window maximized
print(gcf, sprintf('VMode%d.bmp', k), '-r300', '-dbmp'); % exportgraphics() does not support bmp but print does.
savefig(gcf, sprintf('VMode%d', k))
Turbulence Analysis
Turbulence Analysis 2020 年 10 月 16 日
Hi,
Indeed it displays figure, but it's not saved in the destination. Got the below error message as well. I have shown my entire for loop here.....
Error using checkArgsForHandleToPrint
MATLAB Graphics handle must be a figure.
Error in checkArgsForHandleToPrint
Error in print>LocalCreatePrintJob (line 101)
handles = checkArgsForHandleToPrint(0, varargin{:});
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
figure (2)
for k = 2:1:2
New1 = UU(1:ni*nk,k);
New2 = UU(1+ni*nk:2*ni*nk,k);
New3 =reshape (New1,ni,nk);
New4 = reshape (New2,ni,nk);
final = New2;
% New3 = flipud(final);
ax = gca;
colormap(jet);
imagesc(x,y,(New4));
xlabel('x(mm)','FontSize',18,'Interpreter','latex');
ylabel('y(mm)','FontSize',18,'Interpreter','latex');
hold on;
ff = quiver (X', Y', (New3), (New4));
ff.Color='black';
ff.AutoScaleFactor=3;
set(gca, 'YDir','normal')
c1=colorbar('FontSize',25);
colormap(jet);
ax.FontName = 'Cambria';
ax.FontSize=25;
ylim([0 90]);
axis equal
c1.Label.String='\it V (m/s)';
fig = gcf;
fig.WindowState = 'maximized';
pause(2); % pause for some time to let the window maximized
print(gca, sprintf('VMode%d.bmp', k), '-r300', '-dbmp'); % exportgraphics() does not support bmp but print does.
savefig(gcf, sprintf('VMode%d', k))
% saveas(gcf, sprintf('VMode%d', k),'Resolution', 200, 'bmp')
% savefig(gcf, sprintf('VMode%d', k))
end
Ameer Hamza
Ameer Hamza 2020 年 10 月 16 日
Please try the updated code in my previous comment. I have replaced gca with gcf. Usually, print() works pretty well. However, If you get a low-quality image, I recommend using export_fig from file exchange.
Turbulence Analysis
Turbulence Analysis 2020 年 10 月 16 日
Thanks a lot.. Instead of print, I used as below.. Now images are saving in the destination...
fig = gcf;
fig.WindowState = 'maximized';
pause(1);
savefig(gcf, sprintf('VMode%d', k))
saveas(gcf, sprintf('VMode%d', k), 'bmp')
Ameer Hamza
Ameer Hamza 2020 年 10 月 16 日
Yes, If it works for you, then it is fine. However, saveas() usually saves low-resolution files. print() and export_fig() are recommended for a high-resolution images.
Turbulence Analysis
Turbulence Analysis 2020 年 10 月 16 日
Yes, you are correct. usually print yields highre resolution images.
One more query, how to write overbar in the axis title ??

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

その他の回答 (2 件)

KSSV
KSSV 2020 年 10 月 16 日

0 投票

Use this: https://in.mathworks.com/matlabcentral/fileexchange/23629-export_fig for exporting images for better quiality.
Bjorn Gustavsson
Bjorn Gustavsson 2020 年 10 月 16 日

0 投票

To get the figures "just right" you might have to manually masage them a little bit. When it comes to colorbars I often have to resort to manually shift and resize them a little bit to get the numbers and labels inside the printed image-file. I do things like this:
cbh = colorbar;
dx = -0.02;
dWidthx = 0;
set(cbh,'Position',get(cbh,'Position')+[dx 0 dWidthx 0])
to shift the colorbar to the left. Sometimes I make it a bit narrower too, by setting dWidthx to a small negative number.
HTH

カテゴリ

ヘルプ センター および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by