在循环中绘制时填充标记
Filling markers when plotting in a loop
我试图在 MATLAB 中的一个图形中绘制 31 个不同的向量。我正在使用圆形标记 'o' 来绘制每个矢量,我想用不同的颜色绘制每个矢量,而且我还想用 same[=21= 填充标记] 颜色作为标记的边缘。
我正在使用以下代码:
while (n<=31)
plot(x(n),y(n),'o',rand(1,3)) % Not filled markers
n=n+1;
end
问题是因为我使用随机颜色选择,所以当我尝试 运行 以下代码时:
while (n<=31)
plot(x(n),y(n),'o','MarkerFaceColor',rand(1,3)) % Filled markers
n=n+1;
end
标记边缘和标记填充有不同的颜色。我不知道如何解决这个问题,也许我不应该使用随机选择颜色,但我不知道如何解决它,以便在标记边缘和填充中获得相同的颜色。
'MarkerEdgeColor'就是你要的属性,除了FaceColor
while (n<=31)
c = rand(1,3);
plot(x(n),y(n),'o','MarkerFaceColor', c, 'MarkerEdgeColor', c);
n=n+1;
end
我建议使用 scatter
for this rather than creating n
different plot objects that you then have to manage. Using the CData
property 可以为每个数据点设置单独的颜色。
colors = rand(31, 3);
x = rand(31,1);
y = rand(31,1);
s = scatter(x, y, 'filled', 'CData', colors);
我试图在 MATLAB 中的一个图形中绘制 31 个不同的向量。我正在使用圆形标记 'o' 来绘制每个矢量,我想用不同的颜色绘制每个矢量,而且我还想用 same[=21= 填充标记] 颜色作为标记的边缘。
我正在使用以下代码:
while (n<=31)
plot(x(n),y(n),'o',rand(1,3)) % Not filled markers
n=n+1;
end
问题是因为我使用随机颜色选择,所以当我尝试 运行 以下代码时:
while (n<=31)
plot(x(n),y(n),'o','MarkerFaceColor',rand(1,3)) % Filled markers
n=n+1;
end
标记边缘和标记填充有不同的颜色。我不知道如何解决这个问题,也许我不应该使用随机选择颜色,但我不知道如何解决它,以便在标记边缘和填充中获得相同的颜色。
'MarkerEdgeColor'就是你要的属性,除了FaceColor
while (n<=31)
c = rand(1,3);
plot(x(n),y(n),'o','MarkerFaceColor', c, 'MarkerEdgeColor', c);
n=n+1;
end
我建议使用 scatter
for this rather than creating n
different plot objects that you then have to manage. Using the CData
property 可以为每个数据点设置单独的颜色。
colors = rand(31, 3);
x = rand(31,1);
y = rand(31,1);
s = scatter(x, y, 'filled', 'CData', colors);