![]() |
Matlab选择随机颜色进行绘图
我有6个向量要绘制。如何使每个图具有不同的颜色(随机)?使用下面的代码,对于所有六个矢量,该图限制为一种颜色。
plot(x,y,'-rs','LineWidth',1,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',5); [B]回答:[/B] 您可以让[URL="http://www.mathworks.com/help/techdoc/ref/plot.html"]PLOT[/URL]自动为您选择线条颜色。如果所有6个向量的长度都相同,则可以将x和y坐标放入N×6的矩阵X和Y ,并将它们传递给[URL="http://www.mathworks.com/help/techdoc/ref/plot.html"]PLOT[/URL] 。每列将使用不同的颜色: plot(X,Y,'-s'); %# Plots lines with square markers 您还可以使用一些内置的[URL="http://www.mathworks.com/help/techdoc/ref/colormap.html"]颜色图[/URL]来生成一组颜色,然后在分别绘制每条线时使用它们。例如: cmap = hsv(6); %# Creates a 6-by-3 set of colors from the HSV colormap for i = 1:6 %# Loop 6 times plot(X(:,i),Y(:,i),'-s','Color',cmap(i,:)); %# Plot each column with a %# different color end [url=https://stackoverflow.com/questions/3225206]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:16。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.