Multi-Line Colors in 2014

2 ビュー (過去 30 日間)
Sanjay Manohar
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
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
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 件のコメント
Sanjay Manohar
Sanjay Manohar 2015 年 1 月 26 日
Still not understanding.
I have two sets of lines. Have you looked at the original code I posted? If you run my code in Matlab 2013, you will obtain the figure that Matz has posted below as a test. It shows two sets of lines, one for X1, one for X2, overlain, each in the same set of colours, but with different dash styles.
This is so that I can easily compare line set 1 with line set 2. I just want to be able to do this:
plot( X1 )
hold on
plot( X2 , ':' )
hold off
to where X1 and X2 are matrices, and that I can compare line 1 of X1, with line 1 of X2.
When I plot the second set of lines, it used to use the same colours as the first set. However, now since 2014b it does not! And I can't work out the easy way of achieving this seemingly common task.
Image Analyst
Image Analyst 2015 年 1 月 26 日
I don't have R2013b installed anymore. Post screenshots.

サインインしてコメントする。


Matz Johansson Bergström
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 件のコメント
Image Analyst
Image Analyst 2015 年 1 月 24 日
It was changed. Now plot uses different colors each time.
Sanjay Manohar
Sanjay Manohar 2015 年 1 月 24 日
Ah yes it's R2014b ! Sorry.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by