Good day. May I kindly ask anyone to look at the below script and associated Figure and advise on 1). How to manipulate the "Legend" so it doesnt Interfere/hide the time series. 2). Manage the colors of "time series" so they match thier "trend lines"

조회 수: 2 (최근 30일)
figure clf plot(YEARS,S1(2:28,:),'linewidth',2.5) hold on plot(YEARS,S2(1:27,:),'r--','linewidth',2.5) hold on plot(YEARS,S1_trend(2:28,:),'linewidth',2) hold on plot(YEARS,S2_trend(1:27,:),'r--','linewidth',2) axis([1983 2009 -5 5]) h = legend('Ser1', 'Ser2','Ser1-trend','Ser2-trend')

채택된 답변

Ingrid
Ingrid 2016년 2월 5일
please use the documentation of the plot function to see how you can solve this
doc plot
but this is how you can do it
figure
clf
plot(YEARS,S1(2:28,:),'k''linewidth',2.5)
hold on
plot(YEARS,S2(1:27,:),'r','linewidth',2.5)
plot(YEARS,S1_trend(2:28,:),'k--','linewidth',2)
plot(YEARS,S2_trend(1:27,:),'r--','linewidth',2)
axis([1983 2009 -5 5])
h = legend('Ser1', 'Ser2','Ser1-trend','Ser2-trend')
set(h,'Location','EastOutside')
% chose the option that suits you best, for an overview type " doc legend" in the command window
  댓글 수: 5
Mike Garrity
Mike Garrity 2016년 2월 5일
There are several related options here.
If you'd like all of the axes in a figure to use these colors, then you could set them as the default when you create the figure:
figure('DefaultAxesColorOrder',myColors)
If you'd like all of the axes you ever create to use these colors, then you could set them as the default on root.
set(groot,'DefaultAxesColorOrder',myColors)
You could even do that in your startup.m. Then you'd never the see the factory default colors.
Also, one way to make the trend lines match is to use the 'ColorOrderIndex' property to restart the color cycling:
plot(x,y1)
hold on
plot(x,y2)
set(gca,'ColorOrderIndex',1)
plot(x,trend1,'--')
plot(x,trend2,'--')
Here, the plot of trend1 starts with the first color again, and the other trend lines will cycle through the same way the original plots did. This can be useful if the number of datasets isn't a constant.
MattyK
MattyK 2016년 2월 8일
Thanks very much for all your efforts Mike. This will help so much. Much appreciated :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by