Code covered by the BSD License  

Highlights from
lscatter : scatter plot with labels instead of markers

5.0

5.0 | 7 ratings Rate this file 35 Downloads (last 30 days) File Size: 3.63 KB File ID: #28079
image thumbnail

lscatter : scatter plot with labels instead of markers

by

 

30 Jun 2010 (Updated )

Similar to ML's scatter command, but allows you to use separate labels for each point.

| Watch this File

File Information
Description

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.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
20 Aug 2013 Vladimir

Works very good. Thank you!

25 Apr 2013 Bas-Jan

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.

11 Feb 2013 Sisi Ma

this is great!

23 Aug 2011 Andy Yancy

Great, thanks very much.

28 Oct 2010 Adam Auton  
02 Jul 2010 John D'Errico

It works now in my tests.

01 Jul 2010 Yvan Lengwiler

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

30 Jun 2010 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.

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.

Updates
01 Jul 2010

Options are now case insensitive and can be abbreviated, following John D'Errico's comment.

01 Jul 2010

Now also catches ambiguous options, following a further comment by John D'Errico (Thank you, John!).

07 Oct 2010

Bug fix thanks to Christ Ftaclas: before, the label vanished when any of the coordinates became zero. Furthermore, the undocumented 'LineSmoothing' option of the 'plot' command is now supported.

Contact us