自动绘制不同的彩色线 [英] Automatically plot different colored lines
问题描述
我正在尝试在同一张图上绘制几个内核密度估计值,并且希望它们全部为不同的颜色.我有一个模糊的解决方案,使用字符串'rgbcmyk'
并逐步处理每个单独的图,但是经过7次迭代后,我开始出现重复.有没有更简单/更有效的方法来实现这一点,并提供了更多的颜色选择?
I'm trying to plot several kernel density estimations on the same graph, and I want them to all be different colors. I have a kludged solution using a string 'rgbcmyk'
and stepping through it for each separate plot, but I start having duplicates after 7 iterations. Is there an easier/more efficient way to do this, and with more color options?
for n=1:10
source(n).data=normrnd(rand()*100,abs(rand()*50),100,1); %generate random data
end
cstring='rgbcmyk'; % color string
figure
hold on
for n=1:length(source)
[f,x]=ksdensity(source(n).data); % calculate the distribution
plot(x,f,cstring(mod(n,7)+1)) % plot with a different color each time
end
推荐答案
您可以使用诸如HSV之类的颜色图来生成一组颜色.例如:
You could use a colormap such as HSV to generate a set of colors. For example:
cc=hsv(12);
figure;
hold on;
for i=1:12
plot([0 1],[0 i],'color',cc(i,:));
end
MATLAB有13种不同的命名色图('doc colormap'列出了所有这些色图).
MATLAB has 13 different named colormaps ('doc colormap' lists them all).
以不同颜色绘制线条的另一种方法是使用 LineStyleOrder 属性;请参见MATLAB文档中的定义用于绘制线条的颜色更多信息.
Another option for plotting lines in different colors is to use the LineStyleOrder property; see Defining the Color of Lines for Plotting in the MATLAB documentation for more information.
这篇关于自动绘制不同的彩色线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!