下面的代码在Matlab中绘制圆圈.如何指定MarkerEdgeColor
和MarkerFaceColor
中.
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
使用绘图和散射在缩放时奇怪地缩放它们.这不是我想要的.
绘制圆圈有多种选择.最简单的是,实际绘制一个充满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更新图形引擎,这非常顺利:
如果你有一个比R2014b更旧的Matlab版本,你需要坚持使用三角学方法,但是用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
该"决议"通过点数可以自由缩放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