重置ColorOrder索引以在Matlab/Octave中进行绘图 [英] Reset ColorOrder index for plotting in Matlab / Octave

查看:152
本文介绍了重置ColorOrder索引以在Matlab/Octave中进行绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些矩阵x1, x2, ...,其中包含变量个行向量. 我做了连续的情节

I have matrices x1, x2, ... containing variable number of row vectors. I do successive plots

figure
hold all % or hold on
plot(x1')
plot(x2')
plot(x3')

Matlab或八度音阶通常会通过ColorOrder进行迭代,并以不同的颜色绘制每行. 但是我希望每个plot命令再次从颜色顺序中的第一种颜色开始,因此在默认情况下,矩阵中的第一个矢量应为蓝色,第二个应为绿色,第二个应为红色,等等.

Matlab or octave normally iterates through ColorOrder and plot each line in different color. But I want each plot command to start again with the first color in colororder, so in default case the first vector from matrix should be blue, second in green, third in red etc.

不幸的是,我找不到与颜色索引相关的任何属性,而没有其他方法可以重置它.

Unfortunately I cannot find any property related to the color index niether another method to reset it.

推荐答案

您可以在当前轴上移动原始的ColorOrder,以便新图从相同的颜色开始:

You can shift the original ColorOrder in current axes so that the new plot starts from the same color:

h=plot(x1');
set(gca, 'ColorOrder', circshift(get(gca, 'ColorOrder'), numel(h)))
plot(x2');

您可以将其包装在函数中:

You can wrap it in a function:

function h=plotc(X, varargin)
h=plot(X, varargin{:});
set(gca, 'ColorOrder', circshift(get(gca, 'ColorOrder'), numel(h)));
if nargout==0,
    clear h
end
end

并致电

hold all
plotc(x1')
plotc(x2')
plotc(x3')

这篇关于重置ColorOrder索引以在Matlab/Octave中进行绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆