Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot multiple lines with different markers

Tags:

matlab

I would like to plot multiple lines with MATLAB and do it so, that markers would be different in every line. I know that with colours this would be achieved with ColorSet = hsv(12);. Is there some as simple as this method for markers?

like image 431
GC87 Avatar asked Mar 06 '11 12:03

GC87


People also ask

How do you plot different lines in MATLAB?

Plot Multiple Lines By default, MATLAB clears the figure before each plotting command. Use the figure command to open a new figure window. You can plot multiple lines using the hold on command. Until you use hold off or close the window, all plots appear in the current figure window.

How do you plot only markers?

If you specify a marker symbol and do not specify a line style, then plot displays only the markers with no line connecting them. Alternatively, you can add markers to a line by setting the Marker property as a name-value pair. For example, plot(x,y,'Marker','o') plots a line with circle markers.

How do you plot a dashed line in MATLAB?

Create a plot with a red dashed line and circular markers by specifying the linespec argument as '--or' . For this combination, '--' corresponds to a dashed line, 'o' corresponds to circular markers, and 'r' corresponds to red. You do not need to specify all three aspects of the line.


2 Answers

Well, I am not aware of a built-in functionality of MATLAB to do so, but I do the following. I create my own cell:

markers = {'+','o','*','.','x','s','d','^','v','>','<','p','h'}

and then access it this way:

markers{mod(i,numel(markers))+1}

I also created a function, getMarker, that does that and that I added to the path of MATLAB so that I can access it in all my scripts.

like image 155
Greg Avatar answered Oct 20 '22 06:10

Greg


x = linspace(0, 2*pi);
y = cos(bsxfun(@plus, x(1:15:end), x'));
figure
m = {'+','o','*','.','x','s','d','^','v','>','<','p','h'};
set(gca(), 'LineStyleOrder',m, 'ColorOrder',[0 0 0], 'NextPlot','replacechildren')
plot(x, y)
like image 39
Felipe G. Nievinski Avatar answered Oct 20 '22 06:10

Felipe G. Nievinski