Matlab选择随机颜色进行绘图 [英] Matlab choose random color for plotting
问题描述
我有6个向量要绘制. 如何使每个图具有不同的颜色(随机)? 使用下面的代码,对于所有六个向量,该图限制为一种颜色.
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);
推荐答案
您可以拥有 PLOT 自动为您选择线条颜色.如果所有6个向量的长度都相同,则可以将x和y坐标放入N×6矩阵X
和Y
中,并将它们传递给
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
and Y
and pass these to PLOT. A different color will be used for each column:
plot(X,Y,'-s'); %# Plots lines with square markers
您还可以使用一些内置的颜色图来生成一组颜色,然后在分别绘制每条线时使用这些颜色.例如:
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:
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
这篇关于Matlab选择随机颜色进行绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!