Hon*_*nza 11 matlab plot octave
我有x1, x2, ...包含可变数量的行向量的矩阵.我做了连续的情节
figure
hold all % or hold on
plot(x1')
plot(x2')
plot(x3')
Matlab或octave通常迭代ColorOrder并绘制不同颜色的每条线.但是我想让每个plot命令再次以colororder中的第一个颜色开始,所以在默认情况下,矩阵中的第一个矢量应该是蓝色,第二个是绿色,第三个是红色等.
不幸的是我找不到与颜色索引相关的任何属性,而另一种方法是重置它.
您可以ColorOrder在当前轴上移动原件,以便新绘图从相同的颜色开始:
h=plot(x1');
set(gca, 'ColorOrder', circshift(get(gca, 'ColorOrder'), numel(h)))
plot(x2');
你可以将它包装在一个函数中:
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')
小智 6
从R2014b开始,有一种简单的方法可以重新启动颜色顺序.
每次需要重置颜色顺序时插入此行.
set(gca,'ColorOrderIndex',1)
要么
ax = gca;
ax.ColorOrderIndex = 1;
请参阅:http: //au.mathworks.com/help/matlab/graphics_transition/why-are-plot-lines-different-colors.html
定义一个函数,在执行实际绘图之前拦截对 的调用plot并设置'ColorOrderIndex'为1。
function plot(varargin)
if strcmp(class(varargin{1}), 'matlab.graphics.axis.Axes')
    h = varargin{1}; %// axes are specified
else
    h = gca; %// axes are not specified: use current axes
end
set(h, 'ColorOrderIndex', 1) %// reset color index
builtin('plot', (varargin{:})) %// call builtin plot function
我已经在 Matlab R2014b 中对此进行了测试。