How do I set the default linestyle for plots in MATLAB?

前端 未结 1 1618
天命终不由人
天命终不由人 2021-02-02 02:20

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 c

1条回答
  •  伪装坚强ぢ
    2021-02-02 03:02

    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',{'-',':'});
    

    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]);
    

    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.

    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 '-'
    

    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');
    

    0 讨论(0)
提交回复
热议问题