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 visualización (últimos 30 días)
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')

Respuesta aceptada

Ingrid
Ingrid el 5 de Feb. de 2016
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 comentarios
Mike Garrity
Mike Garrity el 5 de Feb. de 2016
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 el 8 de Feb. de 2016
Thanks very much for all your efforts Mike. This will help so much. Much appreciated :)

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by