Matlab选择随机颜色进行绘图
我有 6 个想要绘制的向量。 如何使每个图具有不同的颜色(随机)? 使用下面的代码,绘图将所有六个向量限制为一种颜色。
plot(x,y,'-rs','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',5);
I have 6 vectors which I want to plot.
How I can make each plot with different color (random)?
With the code below, the plot limited to one color for all six vectors.
plot(x,y,'-rs','LineWidth',1,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',5);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以让 PLOT 自动为您选择线条颜色。如果所有 6 个向量的长度相同,则可以将 x 和 y 坐标放入 N×6 矩阵
X
和Y
并将它们传递给 绘图。每列将使用不同的颜色:您还可以使用一些内置的 colormaps 生成一组颜色,然后在单独绘制每条线时使用这些颜色。例如:
You can have PLOT automatically choose line colors for you. If all 6 of your vectors are the same length, you can put the x and y coordinates into N-by-6 matrices
X
andY
and pass these to PLOT. A different color will be used for each column:You could also use some of the built-in colormaps to generate a set of colors, then use these when you plot each line separately. For example:
要创建随机颜色图,您可以执行以下操作
但是,正如我在对 gnovice 的答案的评论中所述,从颜色图中选择颜色通常会提供更易读的颜色组合。
To create a random color map, you could do the following
However, as I stated in my comment to gnovice's answer, picking colors out of a colormap generally provides much more readable color combinations.