Plot MarkerSize units normalized

조회 수: 12 (최근 30일)
Alessandro Masullo
Alessandro Masullo 2013년 12월 4일
댓글: Alessandro Masullo 2013년 12월 4일
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.

채택된 답변

Walter Roberson
Walter Roberson 2013년 12월 4일
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.

추가 답변 (1개)

Kelly Kearney
Kelly Kearney 2013년 12월 4일
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
Alessandro Masullo
Alessandro Masullo 2013년 12월 4일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by