本文介绍了如何绘制实心圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码在Matlab中绘制圆圈.如何在其中指定MarkerEdgeColor
和MarkerFaceColor
.
The below code plots circles in Matlab. How can I specify the MarkerEdgeColor
and MarkerFaceColor
in it.
function plot_model
exit_agents=csvread('C:\Users\sony\Desktop\latest_mixed_crowds\December\exit_agents.csv');
%scatter(exit_agents(:,2),exit_agents(:,3),pi*.25^2,'filled');
for ii =1:size(exit_agents,1),
circle(exit_agents(ii,2),exit_agents(ii,3),0.25);
end
end
function h = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
hold off
end
在缩放时,使用图和散点会怪异地缩放它们.这不是我想要的.
Using plot and scatter scales them weirdly when zooming. This is not what I wish for.
推荐答案
有 各种选项 绘制圆圈.最简单的方法是实际绘制> 填充的rectangle
:
%// radius
r = 2;
%// center
c = [3 3];
pos = [c-r 2*r 2*r];
r = rectangle('Position',pos,'Curvature',[1 1], 'FaceColor', 'red', 'Edgecolor','none')
axis equal
随着 R2014b 图形引擎的更新,这真的很顺畅:
With the update of the graphics engine with R2014b this is really smooth:
如果您使用的Matlab版本低于 R2014b ,则需要坚持使用三角法,但是请使用 fill
进行填充:
If you have an older version of Matlab than R2014b, you will need to stick with your trigonometric approach, but use fill
to get it filled:
%// radius
r = 2;
%// center
c = [3 3];
%// number of points
n = 1000;
%// running variable
t = linspace(0,2*pi,n);
x = c(1) + r*sin(t);
y = c(2) + r*cos(t);
%// draw filled polygon
fill(x,y,[1,1,1],'FaceColor','red','EdgeColor','none')
axis equal
分辨率" 可以根据点数n
自由缩放.
The "resolution" can be freely scaled by the number of points n
.
您的函数将如下所示
function h = circle(x,y,r,MarkerFaceColor,MarkerEdgeColor)
hold on
c = [x y];
pos = [c-r 2*r 2*r];
r = rectangle('Position',pos,'Curvature',[1 1], ...
'FaceColor', MarkerFaceColor, 'Edgecolor',MarkerEdgeColor)
hold off
end
这篇关于如何绘制实心圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!