MATLAB Answers

Plotting different line colors within subplots avoiding duplicate colors?

조회 수: 38(최근 30일)
Conal Doyle
Conal Doyle 28 Jun 2013
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

로그인 to comment.

채택된 답변

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

  댓글 수: 1

로그인 to comment.

More Answers (2)

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

  댓글 수: 0

로그인 to comment.


Tom
Tom 28 Jun 2013
Or:
set(gca,'NextPlot','ReplaceChildren','ColorOrder',cell2mat(C'))
plot(Volume_Major,'LineWidth',2)

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by