Thread Subject: Density scatter plots in Matlab

Subject: Density scatter plots in Matlab

From: Andrew

Date: 14 Jul, 2008 00:55:03

Message: 1 of 7

Hello,

I am new to Matlab, and I am wondering if someone here can
help me with scatter plots.

I have some code that computes some energies, etc., and I
created a simple scatter plot of a dependent variable
versus an independent variable. The code is partially
random in parts.

If I create a scatter plot and tell my function to plot a
large number of data points--100,000, for example--the
points are all plotted, but since there are so many, the
scatter plot becomes in most areas of the plot just a
solid colored blob. Only at the edges of the plot can I
see individual points, because the code is written such
that there is low probability of having a point along
these "fringes."

One way to avoid this solid colored blob of a scatter plot
would be to take less data points. However, because of
the way my code works, I do not want to do this.

What I would really like is a scatter plot that is colored
coded. A certain color would correspond to a certain
range of numbers of points that are in a certain area of
the plot. In other words, I would like to make a color
coded "density" plot.

I can't seem to find a way to do this in the documentation
for the scatter command.

Do you know if there is a way to create such color coded
density plots?

Thanks.

Subject: Density scatter plots in Matlab

From: matt dash

Date: 14 Jul, 2008 01:17:01

Message: 2 of 7

"Andrew " <rearwindow1954@yahoo.com> wrote in message
<g5e857$pml$1@fred.mathworks.com>...
> Hello,
>
> I am new to Matlab, and I am wondering if someone here can
> help me with scatter plots.
>
> I have some code that computes some energies, etc., and I
> created a simple scatter plot of a dependent variable
> versus an independent variable. The code is partially
> random in parts.
>
> If I create a scatter plot and tell my function to plot a
> large number of data points--100,000, for example--the
> points are all plotted, but since there are so many, the
> scatter plot becomes in most areas of the plot just a
> solid colored blob. Only at the edges of the plot can I
> see individual points, because the code is written such
> that there is low probability of having a point along
> these "fringes."
>
> One way to avoid this solid colored blob of a scatter plot
> would be to take less data points. However, because of
> the way my code works, I do not want to do this.
>
> What I would really like is a scatter plot that is colored
> coded. A certain color would correspond to a certain
> range of numbers of points that are in a certain area of
> the plot. In other words, I would like to make a color
> coded "density" plot.
>
> I can't seem to find a way to do this in the documentation
> for the scatter command.
>
> Do you know if there is a way to create such color coded
> density plots?
>
> Thanks.

I'm pretty sure there's a file on the file exchange that
does this, but I'm not sure how well it works with really
big data sets. Here's what i like to do: randomly choose 80%
of your points, plot them in a light color. Choose another
10%, plot them in a darker shade. Choose another 6%, plot
them in an even darker shade. Plot the rest of the points in
the darkest shade.

If this doesnt make sense, just try it and see. It's not
"exact" but its very quick and easy and will show the
interior pattern. (It looks even better on a black
background, plotting from dark to light)

Subject: Density scatter plots in Matlab

From: Peter Perkins

Date: 14 Jul, 2008 14:25:23

Message: 3 of 7

matt dash wrote:
> "Andrew " <rearwindow1954@yahoo.com> wrote in message
> <g5e857$pml$1@fred.mathworks.com>...
>>
>> What I would really like is a scatter plot that is colored
>> coded. A certain color would correspond to a certain
>> range of numbers of points that are in a certain area of
>> the plot. In other words, I would like to make a color
>> coded "density" plot.
>>
>> I can't seem to find a way to do this in the documentation
>> for the scatter command.
>>
>> Do you know if there is a way to create such color coded
>> density plots?
>>
>> Thanks.
>
> I'm pretty sure there's a file on the file exchange that
> does this

This may be what Matt is referring to:

<http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=13352&objectType=file>

Subject: Density scatter plots in Matlab

From: Ken Garrard

Date: 14 Jul, 2008 15:13:03

Message: 4 of 7

Peter Perkins <Peter.PerkinsRemoveThis@mathworks.com> wrote
in message <g5fnkj$rkc$2@fred.mathworks.com>...
> matt dash wrote:
> > "Andrew " <rearwindow1954@yahoo.com> wrote in message
> > <g5e857$pml$1@fred.mathworks.com>...
> >>
> >> What I would really like is a scatter plot that is
colored
> >> coded. A certain color would correspond to a certain
> >> range of numbers of points that are in a certain area
of
> >> the plot. In other words, I would like to make a
color
> >> coded "density" plot.
> >>
> >> I can't seem to find a way to do this in the
documentation
> >> for the scatter command.
> >>
> >> Do you know if there is a way to create such color
coded
> >> density plots?
> >>
> >> Thanks.
> >
> > I'm pretty sure there's a file on the file exchange that
> > does this
>
> This may be what Matt is referring to:
>
> <http://www.mathworks.com/matlabcentral/fileexchange/
loadFile.do?objectId=13352&objectType=file>

Or try plot3k, which I takes about 3 secs to plot the peaks
function with 1001x1001 data points.

http://www.mathworks.com/matlabcentral/fileexchange/
loadFile.do?objectId=9519&objectType=file

Ken

Subject: Density scatter plots in Matlab

From: Andrew

Date: 14 Jul, 2008 16:12:02

Message: 5 of 7

Peter Perkins <Peter.PerkinsRemoveThis@mathworks.com>
wrote in message <g5fnkj$rkc$2@fred.mathworks.com>...
> matt dash wrote:
> > "Andrew " <rearwindow1954@yahoo.com> wrote in message
> > <g5e857$pml$1@fred.mathworks.com>...
> >>
> >> What I would really like is a scatter plot that is
colored
> >> coded. A certain color would correspond to a certain
> >> range of numbers of points that are in a certain area
of
> >> the plot. In other words, I would like to make a
color
> >> coded "density" plot.
> >>
> >> I can't seem to find a way to do this in the
documentation
> >> for the scatter command.
> >>
> >> Do you know if there is a way to create such color
coded
> >> density plots?
> >>
> >> Thanks.
> >
> > I'm pretty sure there's a file on the file exchange
that
> > does this
>
> This may be what Matt is referring to:
>
>
<http://www.mathworks.com/matlabcentral/fileexchange/loadFi
le.do?objectId=13352&objectType=file>

Peter Perkins,

Thanks so much for the link! The code looks very
helpful. One question, though: is it just me, or does it
seem like the third axis of the plot is always on the
order of 10^(-3), no matter how many data points I include
on the plot? For example, if you just run the sample code
given in the file, the height of the "peak" is
approximately 0.95*10^(-3). Do you know why this is so?

Again, thank you SO much for your help. It really helps
me out.

Best Wishes,

Andrew

Subject: Density scatter plots in Matlab

From: Peter Perkins

Date: 14 Jul, 2008 16:55:18

Message: 6 of 7

Andrew wrote:

> One question, though: is it just me, or does it
> seem like the third axis of the plot is always on the
> order of 10^(-3), no matter how many data points I include
> on the plot? For example, if you just run the sample code
> given in the file, the height of the "peak" is
> approximately 0.95*10^(-3). Do you know why this is so?

Well, it's a density plot, so regardless of how much data you have, the surface
has to integrate to 1. I suspect that's what you're seeing. I can only refer
you to the cited paper for details of the plot.

Subject: Density scatter plots in Matlab

From: matt dash

Date: 14 Jul, 2008 17:40:19

Message: 7 of 7

Yep that's the file i was talking about. Although you might
still want to try the method I suggested if knowing the
exact point locations is important (like if the exact shape
of the boundary matters, ie knowing where you go from having
sparse data to zero data). If you're working with something
like normal distributions this doesn't matter since in
theory there is no boundary, but if you're using bounded
distributions there is a definate boundary. With the FEX
solutions you get smoother density coloration, but any small
structures like this in your data get smoothed out.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com