Multi-Line Colors in 2014
Ältere Kommentare anzeigen
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!
Akzeptierte Antwort
Weitere Antworten (2)
Image Analyst
am 24 Jan. 2015
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 Kommentare
Sanjay Manohar
am 24 Jan. 2015
Bearbeitet: Sanjay Manohar
am 24 Jan. 2015
Image Analyst
am 24 Jan. 2015
Bearbeitet: Image Analyst
am 24 Jan. 2015
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
am 25 Jan. 2015
Bearbeitet: Sanjay Manohar
am 25 Jan. 2015
Image Analyst
am 25 Jan. 2015
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
am 25 Jan. 2015
Bearbeitet: Sanjay Manohar
am 25 Jan. 2015
Image Analyst
am 25 Jan. 2015
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
am 26 Jan. 2015
Image Analyst
am 26 Jan. 2015
I don't have R2013b installed anymore. Post screenshots.
Matz Johansson Bergström
am 24 Jan. 2015
1 Stimme
That's odd. I'm using Matlab R2014a and it seems to be working fine. Are you using Matlab R2014b?
2 Kommentare
Image Analyst
am 24 Jan. 2015
It was changed. Now plot uses different colors each time.
Sanjay Manohar
am 24 Jan. 2015
Kategorien
Mehr zu Spline Postprocessing finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!