Label more than 7 lines in a plot

34 ビュー (過去 30 日間)
MiauMiau 2016 年 9 月 29 日
コメント済み: Adam 2016 年 9 月 29 日
I am realizing that after 7 lines, Matlab seems to run out of colors for graphs and that correct? Currently I am plotting the following:
matA is a 200x8 matrix, but after plotting I see that the lines 1 and 8 both have the same colors..what is the easiest way out?

回答 (2 件)

Renato Agurto
Renato Agurto 2016 年 9 月 29 日
one solution is to plot in different lines styles:
hold on;
plot(matA(:,1:7), '-');
plot(matA(:,8:14), '--');
In your example
hold on;
plot(matA(:,1:7), '-');
plot(matA(:,8), '--');
or maybe:
hold on;
plot(matA(:,1:4), '-');
plot(matA(:,5:8), '--');

Adam 2016 年 9 月 29 日
編集済み: Adam 2016 年 9 月 29 日
You can set your own colours for lines you plot and you can also specify the colours used on an axes by setting the
property of an axes. By default this is a 7x3 array. You can extend it or replace it with any number of rows you want so long as it is nx3.
The legend doesn't run out of colours either, it just reflects the colours assigned to the plots so if they repeat then obviously so does it otherwise it would not be reflecting the curves correctly.
  2 件のコメント
Adam 2016 年 9 月 29 日
It looks as though the plot function over-rides these so you have to set the default axes color order before plotting instead - e.g.
set(groot,'defaultAxesColorOrder', newColors)
doSomePlotting( )
If you want to return to the defaults after you can type:
set(groot,'defaultAxesColorOrder', 'default' )



Community Treasure Hunt

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

Start Hunting!

Translated by