我有矩阵x1, x2, ...
,包含变量,行向量的数。我做了连续的计划
figure
hold all % or hold on
plot(x1')
plot(x2')
plot(x3')
Matlab或octave通常通过ColorOrder
迭代,并绘制不同颜色的每行。但是我希望每个plot
命令都以彩色中的第一个颜色重新开始,因此在默认情况下,来自矩阵的第一个向量应该是蓝色的,第二个是绿色的,第三个是红色的等等。
不幸的是,我找不到任何属性与颜色索引尼醚,另一种方法,以重置它。
发布于 2015-05-12 08:11:44
您可以在当前轴上移动原始的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')
发布于 2015-10-16 02:20:01
从R2014b开始,有一个重新启动颜色顺序的简单方法。
每次需要重置颜色顺序时,请插入此行。
set(gca,'ColorOrderIndex',1)
或
ax = gca;
ax.ColorOrderIndex = 1;
发布于 2015-05-12 08:10:09
定义一个函数,该函数在执行实际绘图之前拦截对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中测试了这一点。
https://stackoverflow.com/questions/30183701
复制相似问题