0

Is there some way to plot more than 4 line styles in Matlab (as it is stated here https://www.mathworks.com/help/matlab/creating_plots/specify-line-and-marker-appearance-in-plots.html), I mean line styles without markers?

I 've tried https://www.mathworks.com/matlabcentral/fileexchange/1892-dashline but there is some problem, it does not display line correct in the legend.

Next solution for me is gnuplot, but I have whole calculation in Matlab. Is there any other advice, what other to use or what to do with Matlab to make more than 4 line styles? Will there be more line styles in next Matlab version?

2
  • 2
    There have been only four stiles since I can remember. I’ve been using MATLAB since the early 1990’s. They’re unlikely to add line styles soon. You could play with line thickness, and the most common thing is to use colors. But really, you should be asking yourself if plotting more than two lines to the same axes creates a readable plot. If they’re physically separate, you can label each line directly (use text). If they cross and occupy the same physical space, you’re creating a mess that is hard to read. Commented Mar 14, 2022 at 15:22
  • I agree with Cris. I really think you'll do better using markers than linestyles. But if you don't like markers, color and weight certainly add something to the line's "style".
    – Al Ro
    Commented Mar 16, 2022 at 5:20

1 Answer 1

1

There are only 4 line styles, and realistically that's probably a reasonable limit in terms of legibility. But there are lots of marker styles, why not make your own "lines" by plotting close together markers?

x = 1:0.01:2;
a = sin(x);
b = sin(x) - sort(rand(size(x))/4);
c = sin(x) + sort(rand(size(x))/10);

figure;
hold on
plot( x, a, 'linestyle', 'none', 'marker', 's' );
plot( x, b, 'linestyle', '-', 'marker', 'o' );
plot( x, c, 'linestyle', '-', 'marker', '*', 'linewidth', 1, 'markersize', 5);

plot

You might need to do some interpolation to upsample your data to create the line illusion from close-together markers, interp1 is a simple way to do this.

Although I would echo Cris's comment, your plot will quickly become cluttered, consider using subplots, colours, or other devices to illustrate different series and avoid chart clutter.

Not the answer you're looking for? Browse other questions tagged or ask your own question.