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"

1 次查看(过去 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.

请先登录,再进行评论。

更多回答(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