Multi-Line Colors in 2014
이전 댓글 표시
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!
채택된 답변
추가 답변 (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
Sanjay Manohar
2015년 1월 24일
편집: Sanjay Manohar
2015년 1월 24일
Image Analyst
2015년 1월 24일
편집: Image Analyst
2015년 1월 24일
I don't think you can reset the color order index unless you call cla though I could be wrong, so you need to get the color order:
% Get the initial set of default plot colors.
defaultColorOrder = get(gca,'ColorOrder');
Then keep track of what color to use, say in a variable called colorIndex.
plot(X1, '-', 'color', defaultColorOrder(colorIndex,:));
hold on;
plot(X2, ':', 'color', defaultColorOrder(colorIndex+1,:)); % Or whatever...
Then do whatever you need to do and whenever you want to go back to the first color, just do this:
colorIndex = 1;
Sanjay Manohar
2015년 1월 25일
편집: Sanjay Manohar
2015년 1월 25일
Image Analyst
2015년 1월 25일
No, you don't need a loop. But you have to specify the color if you want to specify the color. It doesn't just automatically give blue each call to plot() like it used to. It will cycle through a bunch of colors. If you want the first default color, you need to specify that.
Sanjay Manohar
2015년 1월 25일
편집: Sanjay Manohar
2015년 1월 25일
Image Analyst
2015년 1월 25일
Sorry, I didn't notice it was a 2D array. You can plot the lines and the markers both in one call to plot(), you don't need two or a loop:
plot( X2, cm, ':-')
Sanjay Manohar
2015년 1월 26일
Image Analyst
2015년 1월 26일
I don't have R2013b installed anymore. Post screenshots.
Matz Johansson Bergström
2015년 1월 24일
1 개 추천
That's odd. I'm using Matlab R2014a and it seems to be working fine. Are you using Matlab R2014b?
댓글 수: 2
Image Analyst
2015년 1월 24일
It was changed. Now plot uses different colors each time.
Sanjay Manohar
2015년 1월 24일
카테고리
도움말 센터 및 File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!