# Box plot + Scatter plot2

Posted by Jiro Doke,

Jiro's pick this week is notBoxPlot by Rob Campbell.

If you have ever used boxplot from the Statistics Toolbox, you know the value of being able to visualize statistical information on a plot.

pts1 = randn(20, 5);
pts2 = randn(10, 40);

figure;
subplot(2, 1, 1);
boxplot(pts1);
subplot(2, 1, 2);
boxplot(pts2, 'plotstyle', 'compact');

While box plots give the statistical information, you may also want the additional insight that you get from the raw data points. You can do that by holding the graph and plotting the data. Or you can just use Rob's function, which overlays the original data in a clever way, with some jitter to better distinguish the points.

figure;
subplot(2, 1, 1)
notBoxPlot(pts1);
subplot(2, 1, 2)
h = notBoxPlot(pts2);
d = [h.data];
set(d(1:4:end), 'markerfacecolor', [0.4,1,0.4], 'color', [0,0.4,0]);
set(d, 'markersize', 3);

There are quite a few entries on File Exchange that are related to boxplots, but I was quite intrigued by Rob's way of visualizing the data points. I like how he extended an existing functionality in the toolbox to create his reusable function. His function has a well-written help text with many examples, and I appreciate the healthy discussions he has on the entry page with some of the users of his function.

Give it a try and let us know what you think here or leave a comment for Rob.

Get the MATLAB code

Published with MATLAB® 7.13

Kelvin replied on : 1 of 2

Hi,

I’m wondering how I may utilize noBoxPlot to make boxplots with vectors of different lengths.

x = rand(5 , 1); y = rand(10, 1); z = rand(15, 1);   data = nan(15, 3); data(1:5 , 1) = x; data(1:10, 2) = y; data(1:15, 3) = z;   notBoxPlot(data);