Matlab:在实际绘制图形之前如何更改图形的线宽? [英] Matlab: How to change the linewidth in a figure before actually plotting some?

查看:616
本文介绍了Matlab:在实际绘制图形之前如何更改图形的线宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题可能有点像下面的链接,但这对我不起作用... http://nl.mathworks.com/matlabcentral/Answers/102530我如何在Matlab中绘制数字之前更改线宽属性的默认设置

This question maybe a bit like the link below, but this didn't work for me... http://nl.mathworks.com/matlabcentral/answers/102530-how-can-i-change-the-default-settings-for-the-linewidth-property-before-i-plot-a-figure-in-matlab

我正在使用matlab函数,该函数会自动以全屏模式打开您的图形,并在第二个监视器上(如果存在).到目前为止,一切正常.我已经实现了在函数内部设置fontsize的功能,因此无需绘制xlabel(..)等就可以绘制任何内容:

I'm working on a matlab function that automatically opens your figure in full screen mode and on a second monitor if present. So far, everything works fine. I already achieved to set the fontsize inside the function, so whitout plotting anything and without making xlabel(..) etc.:

% Fontsize used at the figure
if ~exist('fontsize_manual','var')|| isempty(fontsize_manual)
    set(gca,'FontSize',16)
else
    set(gca,'Fontsize',fontsize_manual)
end

现在是我的问题:我可以用相同的方式更改图中绘制的线条的线宽吗?因此,在这里也要预先定义函数内部的线宽,然后再在脚本中绘制一些线等.我确实希望这仅适用于您正在处理的图形,以便您可以为每个图形更改此默认"并保存如果需要,它们都具有不同的线宽和字体大小.

Now is my question: Can I change in a same way the linewidth of the lines that will by plotted in the figure? So also here, predefining the linewidth inside the function and later on in your script plotting some lines etc. I do prefer this works only for the figure you're working on, so that you can change this 'default' for each figure and save them all with different linewidth and fontsizes if needed.

我尝试了下面的线,但是那只改变了轴的线宽.

I tried the line below, but that only changed the linewidth of the axis.

set(gca,'LineWidth',2)

有没有人可以帮助我解决这个问题?

Is there anyone who can help me solving this problem?

%---------------------------------------------- -------------------------------------------------- ------------------------------ 下面的答案很好,但是我检测到一个新问题. 通过解决前面的问题,偶然发现了下面的代码:

%------------------------------------------------------------------------------------------------------------------------------ The answer below is nice, but I detected a new problem. The code below in found accidentally by solving the previous problem:

set(gca,'LineWidth',3)

原来,这改变了轴的宽度.但是现在有问题了...同样在这里,这仅适用于第一个数字. (见图)

It turned out this changes the width of the axes. But now the problem... Also here this works only on the first figure. (see figure)

如果在第二幅图中绘制之后我也将此代码放在会话中,则第二幅图中的宽度会发生变化.制作第二个图形时,函数内部似乎未达到正确的句柄或类似的东西.您知道这里可能有什么问题吗?

If I also put this code in my session after the plotting in the second figure, the width in the second figure changes. Looks like the right handle isn't reached, or something like that, inside the function, when making the second figure. Do you have any idea what could be wrong here?

推荐答案

我认为您追求的是DefaultLineLineWidth属性,可以为特定图形(或根)分配值.

I think what you are after is the DefaultLineLineWidth property, to which you can assign a value for a particular figure (or the root).

下面是说明的简单代码;基本上,我创建一个图形,将其"visible"属性设置为"off",并分配默认的线宽(听起来很奇怪...).绘制的线的线宽为4,而之后创建的另一个图的线宽为默认值:

Here is a simple code illustrating; basically I create a figure, set its 'visible' property to 'off' and assign a default line linewidth (that sounds weird...). The line plotted has a linewidth of 4, whereas another plot created after has the default width:

clear
clc

hFig1 = figure('Visible','off'); %// Create figure, set it to not visible.

set(gcf,'DefaultLineLineWidth',4); %// Assign default linewidth.

x = 1:10;
plot(x,x.^2-5);

set(hFig1,'Visible','on')
title('Figure 1','FontSize',16);

hFig2 = figure;
plot(x,2.*x+rand(1,10));
title('Figure 2','FontSize',16);

图:

希望有帮助!

这篇关于Matlab:在实际绘制图形之前如何更改图形的线宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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