如何绘制实心圆?

How to plot a filled circle?

下面的代码在 Matlab 中绘制圆。如何在其中指定 MarkerEdgeColorMarkerFaceColor

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

缩放时使用 plot 和 scatter 会奇怪地缩放它们。这不是我想要的。

to plot circles. The easiest is, to actually plot a filled 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 这真的很流畅:

如果您的 Matlab 版本比 R2014b 旧,您将需要坚持使用三角函数方法,但使用 fill 来填充它:

%// 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

"resolution"可以自由缩放点数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