在Matlab中调整图的大小,以免图被图窗口的边缘截断 [英] Adjusting size of plot in Matlab so that graph does not get cut off by edge of plot window

查看:395
本文介绍了在Matlab中调整图的大小,以免图被图窗口的边缘截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Matlab中创建了一个绘图,但是不幸的是,绘图的侧面被绘图窗口切断了.这是我用来创建情节的代码:

I've created a plot in Matlab, but unfortunately the side of the plot is cut off by the plotting window. Here is the code that I've used to create the plot:

% create a plot with dots and with bold sides
point = num(:, 1);
depth = num(:, 2);
hfig = plot(point, depth, '-s', 'Color', 'k', 'MarkerFaceColor', 'k', 'MarkerEdgeColor', 'k', 'MarkerSize', 10);

% make the outside of the graph bold
set(gca, 'LineWidth', axis_size);
set(gca,'FontSize', ticksize, 'FontName', fontname);
set(gca, 'Position', [0.2 0.2 0.8 0.4])
xlabel('Point Number')
ylabel('Depth (cm)')

以下是输出:

请注意如何截取绘图的一侧.另外,这是一张图片,显示我想要实现的目标:

Notice how the side of the plot has been cut off. Alternately, here is a picture showing what I want to achieve:

我简单地创建了绘图而无需调用set(gca, 'Position', [0.2 0.2 0.8 0.4]),然后通过调整窗口大小来调整绘图大小.

I simply created the plot without the call to set(gca, 'Position', [0.2 0.2 0.8 0.4]), and then resized the plot by resizing the window.

但是我该如何在代码中做到这一点?我还想确保可以将绘图另存为具有相同尺寸的PNG文件.我一直在尝试set()函数的各种组合,但是我一直无法获得想要得到的东西.

But how do I do this in code? I also want to ensure that I can save out the plot as a PNG file with the same dimensions. I've been playing around with various combinations of the set() function, and I've been unable to attain what I want to get.

推荐答案

以下文档(如何使用Matlab制作在打印时尺寸正确的图形)提供了一些示例代码,可用于以适当的方式调整图的大小.

The following document (How to produce figures with Matlab that have the right dimensions when printed) provides some example code that can be used to resize the plot in the proper fashion.

使用了以下代码:

point = num(:, 1);
depth = num(:, 2);

hfig = plot(point, depth, '-s', 'Color', 'k', 'MarkerFaceColor', 'k', 'MarkerEdgeColor', 'k', 'MarkerSize', 10);
set(gca, 'LineWidth', axis_size);
set(gca,'FontSize', ticksize, 'FontName', fontname);
set(gcf,'PaperUnits','centimeters')
xSize = 30; ySize = 5;
xLeft = (21-xSize)/2; yTop = (30-ySize)/2;
set(gcf,'PaperPosition',[xLeft yTop xSize ySize])
set(gcf,'Position',[300 600 xSize*50 ySize*50])

xlabel('Point Number');
ylabel('Depth (cm)');  

这里是结果的图片.这看起来类似于我在上面的问题中发布的内容.我不知道这是否取决于显示器的尺寸和/或屏幕分辨率.

Here is a picture of the result. This looks similar to the one that I posted in my question above. I don't know if this is dependent on monitor size and/or screen resolution.

这篇关于在Matlab中调整图的大小,以免图被图窗口的边缘截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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