Thread Subject: howto: programatically calibrate marker size in scatter

Subject: howto: programatically calibrate marker size in scatter

From: Naor Movshovitz

Date: 18 May, 2009 05:30:03

Message: 1 of 8

Can someone suggest a way to do the following:
Use scatter(x,y,s) to plot particles in the Cartesian plane, where the size of the marker (circle by default) will correspond to the diameter of the particle. The way scatter(x,y,s) works, s is the area of the plotted marker in points. What I need to know is to relate points to the x,y axes units programatically. How can I tell how many 'points' are in range(x)?
Thanks,
-naor

Subject: howto: programatically calibrate marker size in scatter

From: Daniel Armyr

Date: 18 May, 2009 06:23:01

Message: 2 of 8

"Naor Movshovitz" <nmovshov@gmail.com> wrote in message <guqror$m1l$1@fred.mathworks.com>...
> Can someone suggest a way to do the following:
> Use scatter(x,y,s) to plot particles in the Cartesian plane, where the size of the marker (circle by default) will correspond to the diameter of the particle. The way scatter(x,y,s) works, s is the area of the plotted marker in points. What I need to know is to relate points to the x,y axes units programatically. How can I tell how many 'points' are in range(x)?
> Thanks,
> -naor

what you want to do sounds very strange, so go back and think if that is really what you want to do.

Then do the following. I am writing this off the top of my head, so make sure you verify according to my comments.

h = scatter()
g = get( h, 'Parent' ) %g should be a handle to an axes, otherwise search the handle tree till you find it.
set( g, 'Units', 'Centimeters' );
sizeInCentimeters = get( g, 'Position' );
set( g, 'Units', 'Pixels' );
sizeInPixels = get( g, 'Position' );

And there you have all the information you need, given that you take a peek into the documentation.

Subject: howto: programatically calibrate marker size in scatter

From: Naor Movshovitz

Date: 18 May, 2009 20:14:01

Message: 3 of 8

"Daniel Armyr" <firstname@lastname.se> wrote in message <guqus5$6nr$1@fred.mathworks.com>...
> h = scatter()
> g = get( h, 'Parent' ) %g should be a handle to an axes, otherwise search the handle tree till you find it.
> set( g, 'Units', 'Centimeters' );
> sizeInCentimeters = get( g, 'Position' );
> set( g, 'Units', 'Pixels' );
> sizeInPixels = get( g, 'Position' );

This works, thanks.
Except: when zooming or changing axis limits the markers seem to keep their original screen area in points^2 and are no longer matched with the axes. Is there a way to override this behavior?

Subject: howto: programatically calibrate marker size in scatter

From: Daniel Armyr

Date: 19 May, 2009 06:11:01

Message: 4 of 8

Well, you can make a callback and register it to be called whenever someone adjusts the axes. For details, look at the function "changeloglabels" in the file exchange.

I would be very interested to find out why you need this functionality. I really think you are solving the wrong problem.

--DA

Subject: howto: programatically calibrate marker size in scatter

From: Naor Movshovitz

Date: 19 May, 2009 06:31:01

Message: 5 of 8

"Daniel Armyr" <firstname@lastname.se> wrote in message <gutihl$5in$1@fred.mathworks.com>...
> Well, you can make a callback and register it to be called whenever someone adjusts the axes. For details, look at the function "changeloglabels" in the file exchange.
>
> I would be very interested to find out why you need this functionality. I really think you are solving the wrong problem.
>
> --DA

Good idea - I didn't know you can get an arbitrary function to be called when the axes change.

Why do you say this is a strange functionality? To me it seems like the most natural thing to do. Many physical problems involve particles in 2-D space. If they are not point particles they have a size. Size is measured in the same units as distance. In my application the average separation between particles is of the order of the particle sphere of influence, represented by a radius. It makes sense to plot them using the same scale. I need to be able to *interactively* identify which particles are within the sphere of influence (or "size") of which other particles. The sphere of influence is best visualized as a sphere - located at (x,y) and extending a radius S (in the same units as x and y!) in all directions. What better way is there to plot these spheres/particles?

Subject: howto: programatically calibrate marker size in scatter

From: Pekka Kumpulainen

Date: 19 May, 2009 07:19:02

Message: 6 of 8

"Naor Movshovitz" <nmovshov@gmail.com> wrote in message <gutjn5$hhq$1@fred.mathworks.com>...
> "Daniel Armyr" <firstname@lastname.se> wrote in message <gutihl$5in$1@fred.mathworks.com>...
> > Well, you can make a callback and register it to be called whenever someone adjusts the axes. For details, look at the function "changeloglabels" in the file exchange.
> >
> > I would be very interested to find out why you need this functionality. I really think you are solving the wrong problem.
> >
> > --DA
>
> Good idea - I didn't know you can get an arbitrary function to be called when the axes change.
>
> Why do you say this is a strange functionality? To me it seems like the most natural thing to do. Many physical problems involve particles in 2-D space. If they are not point particles they have a size. Size is measured in the same units as distance. In my application the average separation between particles is of the order of the particle sphere of influence, represented by a radius. It makes sense to plot them using the same scale. I need to be able to *interactively* identify which particles are within the sphere of influence (or "size") of which other particles. The sphere of influence is best visualized as a sphere - located at (x,y) and extending a radius S (in the same units as x and y!) in all directions. What better way is there to plot these spheres/particles?

Ok, the functionality is not so strange, but the way you were solving it is not so obvious.
If you need circles of specific size, (is that what you need?)
You can use rectangle:
c = [1 2]; % center
r = 1; % radius
pos = [c-r 2*r 2*r];
h = rectangle('Position', pos, 'Curvature',1);

Or.You might not like the way it behaves when zooming, so you can draw a single line:
N = 200;
Fi = linspace(0,2*pi,N);
x0 = 6; y0 = 5; r = 3;
x = x0 + r*cos(Fi);
y = y0 + r*sin(Fi);
plot(x,y)


There are also several contributions to draw ellipses in the FEX

Subject: howto: programatically calibrate marker size in scatter

From: Naor Movshovitz

Date: 19 May, 2009 17:59:02

Message: 7 of 8

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <gutmh6$dri$1@fred.mathworks.com>...
> Ok, the functionality is not so strange, but the way you were solving it is not so obvious.
> If you need circles of specific size, (is that what you need?)
> You can use rectangle:
> c = [1 2]; % center
> r = 1; % radius
> pos = [c-r 2*r 2*r];
> h = rectangle('Position', pos, 'Curvature',1);
>
> Or.You might not like the way it behaves when zooming, so you can draw a single line:
> N = 200;
> Fi = linspace(0,2*pi,N);
> x0 = 6; y0 = 5; r = 3;
> x = x0 + r*cos(Fi);
> y = y0 + r*sin(Fi);
> plot(x,y)
>
>
> There are also several contributions to draw ellipses in the FEX

These are some good ideas. I'll give it a try. I do need to plot a few thousand of these circles which is why I like the fact that scattergroup objects can be referenced by one handle, but maybe an array of rectangles will not be so bad after all.
Thanks for the responses!

Subject: howto: programatically calibrate marker size in scatter

From: Pekka Kumpulainen

Date: 20 May, 2009 07:19:01

Message: 8 of 8

"Naor Movshovitz" <nmovshov@gmail.com> wrote in message <guus16$c44$1@fred.mathworks.com>...
> "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <gutmh6$dri$1@fred.mathworks.com>...
> > Ok, the functionality is not so strange, but the way you were solving it is not so obvious.
> > If you need circles of specific size, (is that what you need?)
> > You can use rectangle:
> > c = [1 2]; % center
> > r = 1; % radius
> > pos = [c-r 2*r 2*r];
> > h = rectangle('Position', pos, 'Curvature',1);
> >
> > Or.You might not like the way it behaves when zooming, so you can draw a single line:
> > N = 200;
> > Fi = linspace(0,2*pi,N);
> > x0 = 6; y0 = 5; r = 3;
> > x = x0 + r*cos(Fi);
> > y = y0 + r*sin(Fi);
> > plot(x,y)
> >
> >
> > There are also several contributions to draw ellipses in the FEX
>
> These are some good ideas. I'll give it a try. I do need to plot a few thousand of these circles which is why I like the fact that scattergroup objects can be referenced by one handle, but maybe an array of rectangles will not be so bad after all.
> Thanks for the responses!

Scatter will create a separate patch object for each point in your data anyway and combines them in hggroup.
You can collect your lines in a group too if you like, see hggroup.
Even without the group you can set common properties of the lines by referring to the array that contains their handles.
If the size of the spheres is important, I would draw the circles by line objects myself. and write a function for it if I'd need to do it more than once.

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