Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the default linestyle for plots in 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?

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.

like image 343
mor22 Avatar asked Nov 23 '10 16:11

mor22


People also ask

What is the default marker size in Matlab?

The default value for MarkerSize is six points (1 point = 1/72 inch). Note that MATLAB draws the point marker (specified by the '.

How can you change the line styles of Matlab plots?

The yellow line is plotted using the dotted line style and diamond marker. The violet line is plotted using the dash-doted line style and circle marker. You can change the line style, marker, and line width in the plot function for each line according to your requirements.


1 Answers

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');
like image 193
gnovice Avatar answered Dec 27 '22 12:12

gnovice