Plot MarkerSize units normalized
29 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!