Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Plotting different line colors within subplots avoiding duplicate colors?

Asked by Conal Doyle

Conal Doyle (view profile)

on 28 Jun 2013
Accepted Answer by Tom

Tom (view profile)

subplot(2,2,3)

plot(Volume_Major,'LineWidth',2,'color',C);

title ('Evolution of Volume week by week');

xlabel('Time');

ylabel('Volume');

set(gca,'XTick',XTicks);

set(gca,'XTickLabel',XLabels);

legend('EURUSD','EURGBP','EURJPY','USDJPY','GBPUSD','USDCHF','USDCAD','AUDUSD','NZDUSD')

where C is a predefined set {[0 0 1],[1 0.4 0.6],[0 1 1],[1 0 0],[0 1 0],[1 0 1],[0 0.5 0],[0.5 0.5 0.5],[0.7 0.3 0],[1 1 0]}

and Volume_Major is a matrix.

When I plot this I find that an error occurs in the plot. When I change the plot function to plot(Volume_Major,'LineWidth',2), it plots perfectly but colors are duplicated. How do I avoid this?

0 Comments

Conal Doyle

Conal Doyle (view profile)

Tags

Products

No products are associated with this question.

3 Answers

Answer by Tom

Tom (view profile)

on 28 Jun 2013
Accepted answer
h = plot(Volume_Major,'LineWidth',2)
set(h,{'Color'},C')

1 Comment

Conal Doyle

Conal Doyle (view profile)

on 3 Jul 2013

thank you, worked perfectly

Tom

Tom (view profile)

Answer by Walter Roberson

Walter Roberson (view profile)

on 28 Jun 2013
h = plot(Volume_Major,'LineWidth',2);
for K = 1 : length(h)
  set(h(K), 'LineColor', C(K,:));
end

0 Comments

Walter Roberson

Walter Roberson (view profile)

Answer by Tom

Tom (view profile)

on 28 Jun 2013

Or:

set(gca,'NextPlot','ReplaceChildren','ColorOrder',cell2mat(C'))
plot(Volume_Major,'LineWidth',2)

0 Comments

Tom

Tom (view profile)

Contact us