File Exchange

image thumbnail


version (65.3 KB) by Manuel Lera Ramírez
A univariate scatter plot for matlab


Updated 04 Feb 2021

From GitHub

View Version History

View license on GitHub

Draw an Univariate Scatter plot out of a nx2 table with a
categorical/string and a numerical variable, or out of a
numerical array, with groups/categories corresponding
to the columns of the numerical array.
This kind of graph is very popular in biochemistry/biology
Many custom options are available as Name,Value
pairs. For optimal visualization of your data I
recommend to play with 'RangeCut', and also with pbaspect of the plot, it
really changes the appearance.
You need the following functions for this function to work:
+CatTable2Array: included in the file
Also, a very simple function to assign colors is
provided, ColorCoder, you can see several examples in the
script attached
Please, all your feedback is welcome to improve this function
If you use this function in a public webpage or publication, I encourage you to share the reference with me so that I include it in the publications section.
version: <1.2> from 20/03/2020
% Manuel Lera Ramírez:
% Developed during Master Thesis Internship in Marcos González-Gaitán's Lab
% Departments of Biochemistry and Molecular Biology, Sciences II,
% 30 Quai Ernest-Ansermet, CH-1211 Geneva 4, Switzerland
Looking at the posts I found a function that does something very similar to this, plotSpread
Look for the one that suits better your needs, the final appearance should be different for each case.
The idea of representing std and SEM as rectangles was inspired by the function notBoxPlot by Rob Campbell

Cite As

Manuel Lera Ramírez (2021). UnivarScatter (, GitHub. Retrieved .

Comments and Ratings (17)

parisa daemi

Works great, thank you!

Jonah Pearl

Wonderful, works seamlessly, thank you!

Chang hsiung

Basílio Gonçalves

Thanks a lot! Really what I needed

Manuel Lera Ramírez

Hello Emily. I dont know what you mean exactly by "by row", but if you have a look at the example, you can see that the function outputs the x and y coordinates of the dots on each group.
If I correctly understand what you mean, this could do the trick:

% Some random data
a = rand(5,1);
b = rand(5,1);
data = [a,b];
% Some rgb assigned to each row
my_rgb = [1 0 0; 0 0 1; 0 1 0; 1 1 0; 0 0 1];
% Draw the plot
[x,y] = UnivarScatter(data);
% Put hold
hold on
% Draw coloured points on top of the plot

Emily Pendleton

Thank you for the code. I am attempting to assign different RGB values to individual points within the same group. I would like to assign the colors by row. Is this possible?

Miquel Serna Pascual


Robin Ehrminger

Manuel Lera Ramírez

The comment of last submission (below) (v. 1.1) does not affect the plotting of the confidence intervals, it just affects the grouping of data in bins for plotting groups that have similar values.

As pointed out by Tommy Kaplan, the function was previously calculating the 90% CI of the mean (from 0.05 to 0.95), changed line 469 in UnivarScatter.m to (0.025 to 0.975) to really get the 95% CI. Many thanks to him and sorry for the inconvenience.

Vahab Youssofzadeh

My bad, the function perfectly takes care of it (my last comment).

Vahab Youssofzadeh

Great function. Wondering how this can be utilized for two groups with different samples. For example, a group with 10 samples vs another with 5 samples.

Peyman Obeidy

Francisco Lera

This code is useful, highly configurable and generates nice plots.

Ale Garci

I was looking for this code for months! Very useful thanks



I'm very pleased with the plots I was able to generate using this code. Thanks for the helpful examples too!

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

Inspired by: notBoxPlot

Inspired: jqu224/masterProject

Community Treasure Hunt

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

Start Hunting!