# Multi-Line Colors in 2014

조회 수: 10(최근 30일)
Sanjay Manohar 2015년 1월 24일
편집: Sanjay Manohar 2015년 1월 26일
In 2013 and earlier I could do this to compare multi-line plots:
% make up some data
X1 = rand(5,3);
X2 = X1+rand(5,3)*0.1;
plot(X1); % draw dataset 1
hold on;
plot(X2,':'); % compare with corresponding dataset 2
hold off;
This is broken in matlab 2014: the second set of lines colours don't match up with the first set.
I guess this is because the axes keep track of the colororder index when hold is on.
How can I reset the colororder index so that subsequent plots restart with color 1, as in previous matlabs? I'd really rather not have to go through a for loop to draw each of the lines!

댓글을 달려면 로그인하십시오.

### 채택된 답변

Sanjay Manohar 2015년 1월 26일
편집: Sanjay Manohar 2015년 1월 26일
Thanks all for your help. For anyone who wants to do this in future:
I finally got the answer by email from Claudette at Mathworks Documentation.
set(gca,'ColorOrderIndex',1)
will reset the colour order, so subsequent plot calls will use the same colour set.
So:
% make up some data
X1 = rand(5,3);
X2 = X1+rand(5,3)*0.1;
plot(X1); % draw dataset 1
hold on;
set(gca,'ColorOrderIndex',1)
plot(X2,':'); % compare with corresponding dataset 2
hold off;
will produce comparable solid and dotted lines.

댓글을 달려면 로그인하십시오.

### 추가 답변(2개)

Image Analyst 2015년 1월 24일
Starting with R2014b you have to explicitly specify a color, otherwise it will use the "next" color in subsequent calls to plot. For example:
plot(X1, 'b-', 'LineWidth', 3); % draw dataset 1
hold on;
plot(X2,'r:', 'MarkerSize', 10); % compare with corresponding dataset 2
grid on;
You might also find it interesting to run my attached colororder demo.
##### 댓글 수: 8표시숨기기 이전 댓글 수: 7
Image Analyst 2015년 1월 26일
I don't have R2013b installed anymore. Post screenshots.

댓글을 달려면 로그인하십시오.

Matz Johansson Bergström 2015년 1월 24일
That's odd. I'm using Matlab R2014a and it seems to be working fine. Are you using Matlab R2014b?
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Sanjay Manohar 2015년 1월 24일
Ah yes it's R2014b ! Sorry.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Graphics Performance in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by