Improving resolution of the plots in Matlab
91 次查看(过去 30 天)
显示 更早的评论
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
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.
回答(1 个)
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: -
- https://in.mathworks.com/help/matlab/creating_plots/save-figure-at-specific-size-and-resolution.html
use exportgraphics to save only the right one and check if you are getting a better ouput.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!