File Exchange

image thumbnail

lscatter : scatter plot with labels instead of markers

version (3.63 KB) by Yvan Lengwiler
Similar to ML's scatter command, but allows you to use separate labels for each point.


Updated 07 Oct 2010

View Version History

View License

Like Matlab's scatter command, lscatter produces a scatter plot. Unlike scatter, it allows you to also use a vector of labels that are used instead of the usual uniform markers.


generates a scatter plot where label{i} is placed at the coordinate (x(i),y(i)), for all i.

The program accommodates a large number of options which make it easy to taylor the output to your needs. The included example script should help you get started.

Please comment if you like it or find it useful.

Cite As

Yvan Lengwiler (2021). lscatter : scatter plot with labels instead of markers (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)

Thomas Coy

Rama Hannineh


Brilliant! Works great

Noel Brizuela

Kshanthi Perera

This is excellent! Thank you so much.


Works very good. Thank you!


Works like a charm, exactly what I needed.

Minor suggestion for improvement: it would be nice if the syntax from the plot-command could be used for the markers/linestyle. For example 'r.' for red dots.

Sisi Ma

this is great!

Andy Yancy

Great, thanks very much.

Adam Auton

John D'Errico

It works now in my tests.

Yvan Lengwiler


Thank you for your comment. It is useful, as usual. I was not even aware of the fact that it is standard in Matlab to have case insensitive property names and that they can be shortened! Now that I know, it will make life easier. I will fix the code accordingly, as soon as I can.

Cheers, Yvan

John D'Errico

Pretty nice. I liked it. Good help. It seems to work in my tests.

My only complaint is what may seem minor. But the best code is friendly code. It helps the user to avoid mistakes.

This works, where L is a cell array of the proper size, but with some missing labels.


I recalled from reading the help that there was a 'missinglabel' property. So I tried this:

??? Error using ==> lscatter at 134
Argument 'missing' is not allowed.

Oh, I thought, did I mis-spell the property name? A standard paradigm in MATLAB for property-value pairs is that property names may be shortened, and that capitalization is ignored. So I checked, and the property name was 'missinglabel'.

??? Error using ==> lscatter at 134
Argument 'missinglabel' is not allowed.

As you might expect from this comment, the property names in this tool are NOT shorten-able, nor is capitalization ignored. So this worked:


The problem is that by failing to satisfy the standard paradigm in MATLAB for property/value pairs, this code is not friendly. It forces you to remember the EXACT name of a property, including capitalization.

The fact is, the extra code to fix this is trivial. All you need to do is to use the function lower (so that case is ignored) and strmatch to identify which property is being specified. In fact, strmatch can catch the shortened property names too.

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: scattertext

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!