View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
plot spread points (beeswarm plot)

4.9 | 8 ratings Rate this file 98 Downloads (last 30 days) File Size: 12.8 KB File ID: #37105 Version: 1.2
image thumbnail

plot spread points (beeswarm plot)


Jonas (view profile)


11 Jun 2012 (Updated )

plotSpread plots distributions of data points, adding jitter to the points to avoid overlap.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

plotSpread allows creating "beeswarm plots", i.e. point distributions where jitter has been added to the data points to avoid overlap.
It further allows specifying groups within the data to show the distribution of the groups inside a distribution.
plotSpread is most suited to visualizing distributions with small amounts of data points. If the points become too dense, it becomes difficult to appreciate the relative importance of modes of a distribution, in which case "distributionPlot" should be used.

plotSpread uses the excellent "distinguishable_colors" to choose default colors for different categories.

In addition, the .zip file contains "myErrorbar" (a modification of the built-in errorbar), "repeatEntries" for easy repetition of entries in a list, and "isEven" to test whether a number is even. For both "repeatEntries" and "isEven" there are better alternatives on the File Exchange.


Generate Maximally Perceptually Distinct Colors inspired this file.

This file inspired Violin Plots For Plotting Multiple Distributions (Distribution Plot.M).

Required Products MATLAB
MATLAB release MATLAB 7.9 (R2009b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (21)
11 Feb 2017 Brad Stiritz

Thanks for your work, this is a nice start. Dot plot / beeswarm plot is sorely needed in Matlab!

If you are thinking about doing any further work on this function, would you please take a look at Aron Eklund's beeswarm package for R, at the URL below?

In particular, would you please consider implementing his "square" plot option? This does not generate random jitter, which is distracting in many contexts. It is much easier on the eyes and brain to visually process the "square" beeswarm plot.

Also, Matlab now generates perceptually uniform colors out of the box, via function parula (R2014b and later). If possible, appropriate code changes there would be appreciated as well, please.

11 Oct 2016 Ricardo Falcon Perez

21 Jun 2016 James

James (view profile)

20 Jun 2016 Hector Domingo Orozco Perez

Hello, I have a big question: is there a way to connect points between different conditions?

11 Mar 2016 Pierre M├ęgevand

A very good function that allows a variety of plots and fills a gap in the plotting abilities of MATLAB.

11 Feb 2016 gilgaladt

02 Jul 2015 Jonas

Jonas (view profile)

@Rainer, Eric: As plotSpread returns the handles to the points, you can change the marker color like so: handles=plotSpread(yourData); set(handles{1},'color','r'); Use another string, or a [r,g,b] array to choose a different color.

Comment only
01 Jul 2015 Eric

Eric (view profile)

I had the same problem, and I got around it by tricking the function into using two categories, where the second category is empty. I made an addtional row of NaN on the input data, then made a categoryIdx vector of all zeros, except set the end value to one. This makes the plot technically have 2 categories, though the second category is completely empty and not plotted. Then you just use categoryColor to set your color to whatever color you need.

Comment only
07 Jun 2015 Rainer

Rainer (view profile)

Great submission. I found that there is no way to specify marker colors if there is only ONE group? It always defaults to blue.

Comment only
22 Dec 2014 Jonas

Jonas (view profile)

@Sneha: plotSpread(data, 'showMM', 5) shows standard deviation, plotSpread(data, 'showMM', 4) shows standard error of the mean.

Comment only
18 Dec 2014 Sneha

Sneha (view profile)

Is there a way to add errorbars to the plotSpread graphs?

Comment only
23 Oct 2012 Jonas

Jonas (view profile)

@Yuri: Thank you for the hint. I'll look into fixing this.

Comment only
22 Oct 2012 Yuri K

Yuri K (view profile)

I found that distinguishable_colors function requires makecform function from Image Processing Toolbox. Not every installation has it.

Comment only
11 Oct 2012 Jonas

Jonas (view profile)

To change marker size programmatically, you can use the function "findall" to get the handles for the spots. Say you want to set the marker size to 16 of the black markers, and the figure number is 3, you could write

Comment only
09 Oct 2012 Ana

Ana (view profile)


Thanks for the script!!Is really useful but can you tell me how I change the marker size in your script?


Comment only
07 Jul 2012 Shatrughan


Good script !! Can you implement plotting the mean, median, errorbar, or others with categoryIdx? if yes, how?


13 Jun 2012 peter

peter (view profile)

It works now !!!
Thanks a lot.

12 Jun 2012 Jonas

Jonas (view profile)

@peter: "ismatrix" only appeared in 2010b. I've tried and failed to install 2009b today, so I wasn't able to make sure that I haven't included another incompatible function call. Have you been able to test the new version?

Comment only
12 Jun 2012 peter

peter (view profile)

I am actually running 2010a, but I still do not have it ?

Comment only
11 Jun 2012 Jonas

Jonas (view profile)

ismatrix is a built-in function from a release later than R2009b - sorry for the mis-labeling of plotSpread. I am replacing ismatrx and I'll upload a fixed version soon

Comment only
11 Jun 2012 peter

peter (view profile)

I tested your example and got the following:
I think you forgot to include "ismatrix" function ?
??? Undefined function or method 'ismatrix' for input arguments of type

Error in ==> plotSpread at 196
elseif ismatrix(data)

Comment only
12 Jun 2012 1.1

Replaced the call to ismatrix, which is a function that only appeared in MATLAB after R2009b

11 Feb 2017 1.2

Updated support for categoryLabels, fixed help

Contact us