Plot MarkerSize units normalized

28 views (last 30 days)
Hello! I need to plot a lot of circle of a precise size every small time-step. I was using a for with plot rcos-rsin, but it was very slow. Then I tried scatter that was very faster, but finally I used plot with 'o' parameter and MarkerSize set, that is absolutely the fastest solution. The only problem I have is the size of the marker, that never matches with what I suppose to. I tried changing 'units' to 'normalized' to both gca and gcf, but it doesn't seem to affect the MarkerSize option.
So, how do I get MarkerSize proportional to axes? Thank you.

Accepted Answer

Walter Roberson
Walter Roberson on 4 Dec 2013
Sorry, the MarkerSize is always in points.
curunits = get(gca, 'Units');
set(gca, 'Units', 'Points');
cursize = get(gca, 'Position');
set(gca, 'Units', curunits);
Now cursize(3) is the width in points and cursize(4) is the height in points. You can then calculate an appropriate marker size as a fraction of the axes size. If you want to catch changes in the axes size, hook into the figure ResizeFcn callback.

More Answers (1)

Kelly Kearney
Kelly Kearney on 4 Dec 2013
How were you calling the circle-equation version? And how many objects are you plotting?
I ran a quick test:
ncirc = 10;
npt = 20; % # of points defining each circle
x = rand(ncirc,1)*10;
y = rand(ncirc,1)*10;
r = rand(ncirc,1)*2;
theta = linspace(0, 2*pi, 20);
xc = bsxfun(@plus, x, bsxfun(@times, r, cos(theta)));
yc = bsxfun(@plus, y, bsxfun(@times, r, sin(theta)));
figure;
hold on;
t(1) = timeit(@() scatter(x,y,r*200,'b')); % Just an example... not scaled
t(2) = timeit(@() plot(xc', yc'));
With ncirc = 10:
t =
0.016969 0.061804
And with ncirc = 1000:
t =
0.11602 0.061678
To adjust marker size using plot, you're going to have to create separate graphics objects for each individually-sized marker, so I doubt you would gain a ton of speed.
  1 Comment
Alessandro Masullo
Alessandro Masullo on 4 Dec 2013
I've never used timeit, but this simple example shows what I mean:
x = rand(10000,1);
y = rand(10000,1);
tic, plot(x,y,'o','MarkerSize',10),toc
Elapsed time is 0.005976 seconds.
tic, scatter(x,y,10),toc
Elapsed time is 0.102514 seconds.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!