Thread Subject: scatter too slow

Subject: scatter too slow

From: Mariem

Date: 20 Jan, 2012 18:00:11

Message: 1 of 8

hi, I have particles that I want to display according to longitude, latitude and time. What I need is to plot the particles, according to longitude and latitude, and to color them according to the time (of birth). That's why I used scatter function.
scatter(longitude, latitude, 4, time)
It works very well when I have a small number of particles (10, 20,30,80), but if I use the real numbers that I have to display (100 000 particles and more), it doesn't work at all, and I have to stop the process each time.

I found many codes here to "solve" this kind of problems, but no one works in my case.
Does any one have an idea ?

Subject: scatter too slow

From: ImageAnalyst

Date: 21 Jan, 2012 02:27:28

Message: 2 of 8

On Jan 20, 1:00 pm, "Mariem " <jlassi.mariem.e...@gmail.com> wrote:
> hi, I have particles that I want to display according to longitude, latitude and time. What I need is to plot the particles, according to longitude and latitude, and to color them according to the time (of birth). That's why I used scatter function.
> scatter(longitude, latitude, 4, time)
> It works very well when I have a small number of particles (10, 20,30,80), but if I use the real numbers that I have to display (100 000 particles and more), it doesn't work at all, and I have to stop the process each time.
>
> I found many codes here to "solve" this kind of problems, but no one works in my case.
> Does any one have an idea ?

------------------------------------------------------------------------
You're right, so don't do it that way. Create an image, then set the
pixels in the image to some value that indicates that a particle lives
there. Then display the image with the imshow() or image() function.
You could apply a colormap to make the particles easier to see.

Subject: scatter too slow

From: Matt J

Date: 22 Jan, 2012 19:36:28

Message: 3 of 8

"Mariem" wrote in message <jfca3b$r53$1@newscl01ah.mathworks.com>...
> hi, I have particles that I want to display according to longitude, latitude and time. What I need is to plot the particles, according to longitude and latitude, and to color them according to the time (of birth). That's why I used scatter function.
> scatter(longitude, latitude, 4, time)
> It works very well when I have a small number of particles (10, 20,30,80), but if I use the real numbers that I have to display (100 000 particles and more), it doesn't work at all, and I have to stop the process each time.
>
> I found many codes here to "solve" this kind of problems, but no one works in my case.
> Does any one have an idea ?
====================

You'll have to elaborate on "doesn't work at all". For me, computations of this order of magnitude run pretty fast, as illustrated below, unless half a sec isn't considered fast...

N=200; X=rand(N); Y=rand(N); Z=rand(N);

tic;
scatter(X(:),Y(:),4,Z(:));
toc;
%Elapsed time is 0.517524 seconds.

Subject: scatter too slow

From: per isakson

Date: 22 Jan, 2012 19:36:29

Message: 4 of 8

"Mariem" wrote in message <jfca3b$r53$1@newscl01ah.mathworks.com>...
> hi, I have particles that I want to display according to longitude, latitude and time. What I need is to plot the particles, according to longitude and latitude, and to color them according to the time (of birth). That's why I used scatter function.
> scatter(longitude, latitude, 4, time)
> It works very well when I have a small number of particles (10, 20,30,80), but if I use the real numbers that I have to display (100 000 particles and more), it doesn't work at all, and I have to stop the process each time.
>
> I found many codes here to "solve" this kind of problems, but no one works in my case.
> Does any one have an idea ?

Which codes doesn't work and why do they fail? With 100 000 particles and more the risk is large that points will be hidden by other points.

My answere in

http://www.mathworks.se/matlabcentral/answers/24076-better-way-to-visualize-profile-data

is that one of the codes that doesn't work?

- per
 

Subject: scatter too slow

From: per isakson

Date: 22 Jan, 2012 19:36:31

Message: 5 of 8

"Mariem" wrote in message <jfca3b$r53$1@newscl01ah.mathworks.com>...
> hi, I have particles that I want to display according to longitude, latitude and time. What I need is to plot the particles, according to longitude and latitude, and to color them according to the time (of birth). That's why I used scatter function.
> scatter(longitude, latitude, 4, time)
> It works very well when I have a small number of particles (10, 20,30,80), but if I use the real numbers that I have to display (100 000 particles and more), it doesn't work at all, and I have to stop the process each time.
>
> I found many codes here to "solve" this kind of problems, but no one works in my case.
> Does any one have an idea ?

Which codes doesn't work? With 100 000 particles and more some points will be hidden by other points. Did you see my answere in

http://www.mathworks.se/matlabcentral/answers/24076-better-way-to-visualize-profile-data

/ per

Subject: scatter too slow

From: Val

Date: 23 Jan, 2012 14:06:10

Message: 6 of 8

"Mariem" wrote in message <jfca3b$r53$1@newscl01ah.mathworks.com>...
> hi, I have particles that I want to display according to longitude, latitude and time. What I need is to plot the particles, according to longitude and latitude, and to color them according to the time (of birth). That's why I used scatter function.
> scatter(longitude, latitude, 4, time)
> It works very well when I have a small number of particles (10, 20,30,80), but if I use the real numbers that I have to display (100 000 particles and more), it doesn't work at all, and I have to stop the process each time.
>
> I found many codes here to "solve" this kind of problems, but no one works in my case.
> Does any one have an idea ?

You might search for plot3k in the file exchange. It uses a much more sensible algorithm for scatter plots and I find that I can plot millions of data points with it.

The only problem with it is that it has a bug (whose source I've been unable to find) that prevents it from releasing a plot. So the animation you're describing might not work well. But perhaps you will find the bug and post an update.

Best of luck,

Val

Subject: scatter too slow

From: matt dash

Date: 23 Jan, 2012 21:50:09

Message: 7 of 8

"Mariem" wrote in message <jfca3b$r53$1@newscl01ah.mathworks.com>...
> hi, I have particles that I want to display according to longitude, latitude and time. What I need is to plot the particles, according to longitude and latitude, and to color them according to the time (of birth). That's why I used scatter function.
> scatter(longitude, latitude, 4, time)
> It works very well when I have a small number of particles (10, 20,30,80), but if I use the real numbers that I have to display (100 000 particles and more), it doesn't work at all, and I have to stop the process each time.
>
> I found many codes here to "solve" this kind of problems, but no one works in my case.
> Does any one have an idea ?

Create the plot using "patch" instead of "scatter". Since all your data is the same size, you'll only need one patch. (This is what's happening when you call scatter anyway, so cut out the middleman) Then change the figure renderer to opengl and you shouldn't have a speed problem. (Presuming you have a reasonably good graphics card)

Subject: scatter too slow

From: Pekka Kumpulainen

Date: 26 Jan, 2012 12:29:10

Message: 8 of 8

"Mariem" wrote in message <jfca3b$r53$1@newscl01ah.mathworks.com>...
> hi, I have particles that I want to display according to longitude, latitude and time. What I need is to plot the particles, according to longitude and latitude, and to color them according to the time (of birth). That's why I used scatter function.
> scatter(longitude, latitude, 4, time)
> It works very well when I have a small number of particles (10, 20,30,80), but if I use the real numbers that I have to display (100 000 particles and more), it doesn't work at all, and I have to stop the process each time.
>
> I found many codes here to "solve" this kind of problems, but no one works in my case.
> Does any one have an idea ?

Scatter creates separate patch objects for each data point. This only works for reasonable number of points.
All we would need here is one line with markers and cdata. Unfortunately line objects still don't have cdata property (I have suggested it a few times since about 1995).

You could try my FEX contribution color_line, which seems to work fluently up to 1e6 ponts (didn't try more). It makes a fake line using surface that has the cdata property.
hth

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

Contact us at files@mathworks.com