Matlab保存具有预定义大小的图形 [英] Matlab saving figure with predefined size

查看:87
本文介绍了Matlab保存具有预定义大小的图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有2个图的图.我正在尝试将图形另存为宽度更长的png.

I have a figure with 2 plots on it. I am trying to save the figure as a png with a longer width.

%%%%%%%%%%%%First%%%%%%%%%%%%%%%%%%
a=figure('Name','First Structure');
load C:\Users\William\workspace\P5\FirstAdd.txt
n=FirstAdd(:,1);
t=FirstAdd(:,2);
subplot(1,2,1);
plot(n,t);
xlabel('n');
ylabel('Time');
title('First Structure''s Add');
grid on

load C:\Users\William\workspace\P5\FirstContains.txt
n=FirstContains(:,1);
t=FirstContains(:,2);
subplot(1,2,2);
plot(n,t);
xlabel('n');
ylabel('Time');
title('First Structure''s Contains');
grid on

rect=[250,250,1080,480];
set(a, 'OuterPosition',rect);
print(a,'-dpng','First Structure.png');

在最后3行中,我设置了图形窗口,以使2个图足够宽.但是,当我尝试保存图形时,图像是将其粉碎的默认大小.

In the last 3 lines I set the figure window such that the 2 plots are wide enough. However, when I try to save the figure, the image is its default size in which the plots are squished.

我想念什么?

推荐答案

OuterPosition

The OuterPosition figure property only changes where the figure window is on the screen; it doesn't change how it will print.

Matlab在打印"图形时会使用PaperSizePaperUnitsPaperPosition和类似图形属性,即使它们并没有真正意义,例如在生成位图文件时也是如此. (将PaperUnits设置为pixels是合乎逻辑的,但这是行不通的.)

Matlab uses the PaperSize, PaperUnits, PaperPosition and similar figure properties when "printing" a figure, even when they don't really make sense, such as when producing a bitmap file. (Settings PaperUnits to pixels would be logical, but it doesn't work.)

获取以 pixels 为单位的特定图像尺寸的过程是将PaperPosition设置为以 inches (或其他物理单位)为单位的某个尺寸,然后指定所需的分辨率(每英寸点数),使用print-r选项:

The procedure for getting a particular image size in pixels is to set PaperPosition to some size in inches (or another physical unit) and then specify the desired resolution in dots per inch using the -r option to print:

r = 150; % pixels per inch
set(gcf, 'PaperUnits', 'inches', 'PaperPosition', [0 0 1080 480]/r);
print(gcf,'-dpng',sprintf('-r%d',r), 'bar.png');

print 函数.

您还可以尝试使用-r0选项,告诉Matlab使用显示分辨率.

You could also try the -r0 option which tells Matlab to use the display resolution.

这篇关于Matlab保存具有预定义大小的图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆