我如何设置MATLAB中的地块的默认线性? [英] How do I set the default linestyle for plots in MATLAB?

查看:186
本文介绍了我如何设置MATLAB中的地块的默认线性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要绘制的数据数组

I have an array of data that I would like to plot

temp=0.5*rand(500,10);
[~,offset]=meshgrid(1:500,1:10);
figure(101)
plot(temp+offset')

我将线条样式设置为在线条颜色通过一个周期后自动更改为下一个样式?

How can I set the line style to automatically change to the next style once the line colours have been through one cycle?

对于此示例,我希望第8-10行不同的线条风格。我可以手动做,但我想Matlab为我做,如果我可以设置一个默认选项在某个地方。

For this example I would like the 8-10th lines to have a different line style. I can do it manually but I'd like Matlab to do it for me if I can set a default option somewhere.

推荐答案

您的第一个倾向可能是更改 'LineStyleOrder'属性绘制您的数据之前。不幸的是, PLOT 等高级绘图功能将会重置 'LineStyleOrder'属性为其默认值' - '。一种解决方案是更改所有轴对象在 =http://www.mathworks.com/help/techdoc/ref/rootobject.html>根级别。例如:

Your first inclination might be to just change the 'LineStyleOrder' property of the axes before plotting your data. Unfortunately, high-level plotting functions like PLOT will reset the 'LineStyleOrder' property of the axes to it's default value '-'before plotting. One solution is to change the default value used by all axes objects at the root level. For example:

set(0,'DefaultAxesLineStyleOrder',{'-',':'});

首先使用实线,然后使用虚线, 。请注意,您还可以使用自定义 'ColorOrder'属性与高级绘图函数通过更改根的默认值。以下示例将对其进行更改,因此 PLOT 仅在红色,绿色和蓝色之间循环:

Will first use a solid line, then a dotted line, and then repeat again if necessary for each plot. Note that you could also use a custom 'ColorOrder' property with high-level plotting functions by changing the default value at the root as well. The following example will change it so PLOT cycles between only red, green, and blue:

set(0,'DefaultAxesColorOrder',[1 0 0; 0 1 0; 0 0 1]);

而不是担心不同的线条样式,你的问题的另一个解决方案是设置默认的颜色顺序有超过7种颜色。

Instead of worrying about different line styles, another solution to your problem would be to set the default color order to have more than just 7 colors.

一旦在根上的默认属性值设置,它们将保持这种方式,直到MATLAB关闭。重新打开时,默认属性值将被设置回其工厂定义的值。像 CLEAR 等命令不会将默认属性设置为出厂时定义的值。相反,您应该将默认属性值设置为'remove'以撤消用户定义的值,如下所示:

Once default property values on the root are set, they will stay that way until MATLAB is closed. When reopened, the default property values will be set back to their factory-defined values. Commands like CLEAR won't set default properties back to their factory-defined values. Instead, you should set the default property value to 'remove' to undo user-defined values, like so:

set(0,'DefaultAxesLineStyleOrder','remove');  %# Sets the default back to '-'

另一种方法是更改​​所有轴对象,如果您更改 NextPlot 'replace',然后您可以更改 http://www.mathworks.com/help/techdoc/ref/axes_props.html#LineStyleOrder> 'LineStyleOrder' 'ColorOrder' 属性, a href =http://www.mathworks.com/help/techdoc/ref/plot.html> PLOT 不会将其重置为默认值。例如,这应该做你想要的:

As another alternative to changing the default properties used by all axes objects, if you change the NextPlot property of an individual axes to anything except 'replace' you can then change the 'LineStyleOrder' or 'ColorOrder' properties to whatever you want and PLOT will not reset them to their defaults. For example, this should do what you want as well:

set(gca,'NextPlot','add','LineStyleOrder',{'-',':'});
plot(temp+offset');

这篇关于我如何设置MATLAB中的地块的默认线性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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