Improving resolution of the plots in Matlab

69 ビュー (過去 30 日間)
Go Sugar
Go Sugar 2022 年 10 月 16 日
編集済み: Go Sugar 2022 年 10 月 22 日
Hello :)
I have several matlab plots. When I try to save them in jpg or emf formats, I get poor resolution. I want to obtain a similar resolution like when I save it from matlab.fig file to jpg or emf (with a full screen). Since I have many figures, that is wasting time. Below is the simplest command for a few figures. Is there a way to improve the resolution with saveas command? And do I have to copy and paste each figure to transfer it into word document? I have searched the forum and could not find any suggestions with saveas command for improving the resolution.
Thank you so much. =)
for b=1:4
saveas(figure(b),['FIG' num2str(b'),'.jpg']);
saveas(figure(b),['FIG' num2str(b'),'.emf']);
saveas(figure(b),['FIG' num2str(b'),'.fig']);
end
  10 件のコメント
dpb
dpb 2022 年 10 月 22 日
編集済み: dpb 2022 年 10 月 22 日
%text(1:length(mydata),mydata,num2str(mydata'),'rotation', 90, 'horiz','center');
That's at least one problem -- using 'horizonatlalignment','center' is what is causing the values to be written on top of the bar that contributes greatly to the "messy" look.
Remember that the horizontal and vertical alignments are of the text itself with respect to its own orientation--when you rotate it 90 degrees, 'horizonatalalignment' is STILL with respect to the alignment of the text string from its origin; it is NOT related to the vertical/horizontal direction in the axes -- even though they're the same without rotation, they're flipped when the text is rotated.
Y=randi(100,1,20);
subplot(2,1,1)
hB=bar(Y); ylim([0 100])
text(hB.XEndPoints,hB.YEndPoints,string(hB.YEndPoints),'rotation',90,'horizontalalign','center');
title('Rotated Text, Centered Horizontal Alignment')
subplot(2,1,2)
hB=bar(Y); ylim([0 100])
hT=text(hB.XEndPoints,hB.YEndPoints,[" "+string(hB.YEndPoints)],'Rotation',90);
title('Rotated Text, Left (Default) Horizontal Alignment')
%subplot(3,1,3)
%hB=bar(Y);
%text(hB.XData,hB.YData," "+hB.YData,'rotation',90)
%title('Rotated Text, Left Horizontal Alignment Plus Extra Space')
It would be better/more robust coding to use the X,Y data and positions from the bar object itself (and more generic as well, you don't have to change code if the data change) instead of the hardcoded 1:N above -- what if you actually have a real X variable with other than ordinal values or a categorical??? The above is then wrong where as the other would still work.
Go Sugar
Go Sugar 2022 年 10 月 22 日
編集済み: Go Sugar 2022 年 10 月 22 日
Thank you so much for all the help, you are so nice. =) Now I will be able to fix the messy look of the numbers. =) It will work fine for me. I cannot even put a vote to your comment but it solved the messy look of the numbers. =) In this way, everything looks more organized. Have a great day!

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

回答 (1 件)

Harsha
Harsha 2022 年 10 月 19 日
The “saveas” function uses a resolution of 150 DPI and uses “PaperPosition” and “PaperPositionMode” properties of the figure to determine the size of the image. There is no way to change the resolution of the output using the “saveas” command.
To control the size or resolution when you save a figure, use “print” function instead.
Refer to the following documentation for using the “print” function: -
From MATLAB R2020a you can use the “exportgraphics” function to save any axes, figure, chart that can be child of a figure, tiled chart layout, or container such as panel with specific size, resolution, or background color.
Refer to the following documentation on using “exportgraphics” function: -
use exportgraphics to save only the right one and check if you are getting a better ouput.
  1 件のコメント
Go Sugar
Go Sugar 2022 年 10 月 22 日
Thank you so much for the information. I will check the links provided, be sure that I am not missing anything and see if I get a better output. I will also try representing the data in another way, I have so many bars. I will let you know if I can solve it thank you for your time. =)

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

カテゴリ

Help Center および 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