How to plot partial results of a for-loop in one figure and create different figures for other results?

1 回表示 (過去 30 日間)
I have a for loop, which reads in and evaluates the run-off values for various years. There are several time series for each year. So I have an ensemble of time series per year. Now I want to create a figure for each year, in which the respective ensemble is presented.
The following code section shows the plot function for the year 2014 as an example:
sdatelim=[datenum(2014,05,01) datenum(2014,10,01)];
dt = 1/24;
sdate2014 = sdatelim(1):dt:sdatelim(2);
figure('Position',[200 100 900 900],'PaperPositionMode','auto','Color','w');
a(1) = axes;
set(a(1),'Position',[0.09 0.09 0.80 0.80],'fontsize',13)
hold on;
plot(sdate2014(1:3672),Qs2014,'.'); hold on;
% the next figure for the subsequent year
... figure(...); hold on;
a() = axes ...
plot (sdate2015(1:3672),Qs2015); hold on;
Regardless of whether I add the figure command before the loop or add the hold on, always a separate figure is opened.
This is a solution that did not work.
Now my questions are:
  1. How can I create multiple figures with the corresponding ensemble (that means e.g. all time series for the year 2014 in one figure)?
  2. How can I change the line color within a figure for a few thousand ensemble members?

採用された回答

José-Luis
José-Luis 2017 年 7 月 4 日
  7 件のコメント
José-Luis
José-Luis 2017 年 7 月 4 日
I don't get it. You are not using the ii index inside the loop. Is Qs2014 a 2D array?
If so:
subplot(2,1,1)
plot(sdate2014(1:3672),Qs2014,'Color',rand(1,3));
subplot(2,1,2);
plot(sdate2015(1:3672),Qs2015,'Color',rand(1,3));
Have you tried reading the documentation? It's pretty good --- most of the time.
Glazio
Glazio 2017 年 7 月 5 日
@José-Luis: Thanks, now it works. I have incremented the subplot-handle-number manually, without a for-loop.
For three graphics, this is the easiest solution. I have read the documentation on mathworks.com.
My implementation is:
dt = 1/24;
sdatelima=[datenum(2014,05,01) datenum(2014,10,01)];
sdate2014 = sdatelima(1):dt:sdatelima(2);
sdatelimb=[datenum(2015,05,01) datenum(2015,10,01)];
sdate2015 = sdatelimb(1):dt:sdatelimb(2);
sdatelimc=[datenum(2016,05,01) datenum(2016,10,01)];
sdate2016 = sdatelimc(1):dt:sdatelimc(2);
aH(1) = subplot(3,1,1); hold on;
set(aH(1),'TickDir','out','FontSize',12);
set(gcf,'Renderer','painters');
datetick('x','keeplimits');
ylim([0 20])
xlim(sdatelima)
title(aH(1),'Runoff 2014 - MCS (Ensemble)','fontsize',14,'fontweight','b');
ylabel(aH(1),'Runoff [m^3 s^-^1]','fontsize',13)
xlabel(aH(1),'Date','fontsize',13)
box on;
grid on;
plota = plot(sdate2014(1:3672),Qs2014,'Color',rand(1,3)); hold on;
set(plota,'LineWidth',2.0)
aH(2) = subplot(3,1,2); hold on;
set(aH(2),'TickDir','out','FontSize',12);
set(gcf,'Renderer','painters');
datetick('x','keeplimits');
ylim([0 20])
xlim(sdatelimb)
title(aH(2),'Runoff 2015 - MCS (Ensemble)','fontsize',14,'fontweight','b');
ylabel(aH(2),'Runoff [m^3 s^-^1]','fontsize',13)
xlabel(aH(2),'Date','fontsize',13)
box on;
grid on;
plotb = plot(sdate2015(1:3672),Qs2015,'Color',rand(1,3)); hold on;
set(plotb,'LineWidth',2.0)
aH(3) = subplot(3,1,3); hold on;
set(aH(3),'TickDir','out','FontSize',12);
set(gcf,'Renderer','painters');
datetick('x','keeplimits');
ylim([0 20])
xlim(sdatelimc)
title(aH(3),'Runoff 2016 - MCS (Ensemble)','fontsize',14,'fontweight','b');
ylabel(aH(3),'Runoff [m^3 s^-^1]','fontsize',13)
xlabel(aH(3),'Date','fontsize',13)
box on;
grid on;
plotc = plot(sdate2016(1:3672),Qs2016,'Color',rand(1,3)); hold on;
set(plotc,'LineWidth',2.0)
Thanks for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by