Code covered by the BSD License  

Highlights from


4.5 | 12 ratings Rate this file 154 Downloads (last 30 days) File Size: 30.2 KB File ID: #42560
image thumbnail




10 Jul 2013 (Updated )

An alias of the LINE command, with additional control for markers, in number and location.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

Allows control of nr of markers, and positioning uniformly along x or along the curve, and with the option to lock on a local max.
Accept same inputs as the LINE command, with the additional parameter NUM_MARKERS, specifying how many markers to be plot.
Inspired by the first answer given by Ioannis Filippidis on

Required Products MATLAB
MATLAB release MATLAB 7.12 (R2011a)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
21 Nov 2014 Yonatan Afework

Great work!

21 Nov 2014 Yonatan Afework  
14 Nov 2014 Julio

works very fine. Thank you so much.

21 Oct 2014 Jérémy

Great !
This makes perfectly what I needed.
Thank you for your answer so fast!

( N.B: For Matlab R2009B, the function iscolumn(x) isn't supported, so I simply replaced it with (size(x,2)==1) )

17 Oct 2014 Massimo Ciacci


Yes, there is a workaround to use it in plotyy, that does not require changing line_fewer_markers, just function pointers, as follows:

figure(10); hold on; set(gca,'FontSize',16); set(gca,'FontName','Times'); set(gcf,'Color',[1,1,1]);

f1 = @(x,y)line_fewer_markers(x,y,5,'ro','LegendLine','off');
f2 = @(x,y)line_fewer_markers(x,y,8,'bs','Spacing','curve','markerfacecolor','b');
[u,lh1,lh2] = plotyy(x,y1,x,y2,f1,f2)

legend('curve 1','curve 2')

16 Oct 2014 Jérémy

Hello !
Thank you for this usefull function !

Is there a way to use it on a two Y-axis plot, with plotyy ?

25 Sep 2014 Marie

Nice function! I was desperate with my two lines and non-corresponding legends... Great job !

Is that possible to get a 3D version, like plot3 ?

25 Sep 2014 Marie  
21 Feb 2014 Maria Pershina

Just awesome!!!

13 Feb 2014 David Lindell

Nice one!

21 Dec 2013 Xiaoxia Ye

If the function is able to handle nan data as "plot" does, it will be even more awesome.

13 Sep 2013 Pasumarthi Viswanath  
28 Aug 2013 Pablo

a great function!

19 Aug 2013 Joe  
07 Aug 2013 Emerson

Thanks for the update. Love the results!

07 Aug 2013 Jan Simon

Without doubt the results are a strong optical improvement compared to adding a marker at each point.

06 Aug 2013 Massimo Ciacci

I just added an option to disable line showing up in the legend (so that only the marker will show up). This option is:'LegendLine','off'

05 Aug 2013 Emerson

I am new to Matlab so I don't feel I'm qualified to give a rating or strong comments yet, but this has been very useful to me in achieving an important plot that seems to be almost inexplicably unnatural to achieve with Matlab.

Massimo, could you tell me whether or not it is possible to show only the markers in the legend rather than the markers in addition to the line style? I ask because my plot is only black and white with the same lines style for every curve, and I imagine this isn't uncommon for publications. The preferred legend for this style shows only the markers.

11 Jul 2013

- better formatted text indentation
- fixed few typos in comments
- added abbreviations for marker specs (mk,mks,mfc)

06 Aug 2013

Added option
to inhibit linestyle to show in legend.

20 Aug 2013

- added compatibility for column vector input

17 Oct 2014

- Added support for logarithmic X spacing of markers
- Added example on how to use it with plotyy

17 Oct 2014

same as 2 minutes ago

Contact us