Save a Figure as a .png and .pdf of a Specific Size

27 ビュー (過去 30 日間)
Allen Hammack
Allen Hammack 2022 年 9 月 10 日
回答済み: Simon Chan 2022 年 9 月 11 日
I am trying to generate a plot and save it as .png and .pdf files of a certain size. I have many plots that I am generating that will eventually be put into a Word document. I have found that the plots I am generating appear differently depending on the computer I use. I expect that the reason the plot look differently based on the computer I generate them from is because the different computers have different sized monitors. Here is a simplified script that includes the commands I am using to generate my plot:
xdata = [1,2,3,4];
ydata = [1,4,1,2];
fig = figure('Units','normalized','Position',[0 0 1 1]);
'PaperSize',[15 15])
blue = [0 0.4470 0.7410];
xlabel('Time (min.)','FontSize',20,'Fontweight','bold')
ax_left = gca;
xlim([0 5])
ylim([0 5])
ax = gca;
ax.FontSize = 20;
ax.FontWeight = 'bold';
box on
I am using the "normalized" units option, so the plot appears large on my screen. I am trying to use the "PaperPositionMode," "PaperUnits," "PaperOrientation," and "PaperSize" options to export the plots to a different size that will not change regardless of the computer I use to generate my plots. Right now, I am using an arbitrary 15-inch by 15-inch paper size, but I'm not getting the .png or .pdf files to be that size. Can someone help?

回答 (1 件)

Simon Chan
Simon Chan 2022 年 9 月 11 日
Try this to see whether the following is what you want.
clear; clc;
f = figure;
% Set figure position after plotting. A higher value for higher resolution
% only, you may use a smaller value.
set(f,'Position',[0 0 15000 15000]);
% Set PaperSize and PaperPosition according to 15 inch on both sides
set(f,'PaperSize',[15 15],'PaperPosition',[0 0 15 15]);
% Print figure in png format. You may remove '-r1000' if you don't want to have high resolution image




Community Treasure Hunt

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

Start Hunting!

Translated by