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.
lscatter(x,y,l)
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.
Yvan Lengwiler (2021). lscatter : scatter plot with labels instead of markers (https://www.mathworks.com/matlabcentral/fileexchange/28079-lscatter-scatter-plot-with-labels-instead-of-markers), MATLAB Central File Exchange. Retrieved .
Inspired: scattertext
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
Brilliant! Works great
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.
this is great!
Great, thanks very much.
It works now in my tests.
John,
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
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.
lscatter(X,Y,L)
I recalled from reading the help that there was a 'missinglabel' property. So I tried this:
lscatter(X,Y,L,'missing','?')
??? 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'.
lscatter(X,Y,L,'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:
lscatter(X,Y,L,'MissingLabel','?')
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.