Skip to content

Commit a7b4d26

Browse files
committed
Fix time series axes boundaries
When requesting an arbitrary tstart and/or tend on time series plots, the vertical scale was based on the entire series rather than the zoomed part. The horizontal scale was also always based on the 't' time series rather than actual times at which the time series are available (or the requested tstart/tend).
1 parent c117ee5 commit a7b4d26

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

stagpy/time_series.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@ def plot_time_series(sdat, lovs):
3434
"""
3535
time_marks = _collect_marks(sdat)
3636
for vfig in lovs:
37+
tstart = conf.time.tstart
38+
tend = conf.time.tend
3739
fig, axes = plt.subplots(nrows=len(vfig), sharex=True,
3840
figsize=(12, 2 * len(vfig)))
3941
axes = [axes] if len(vfig) == 1 else axes
4042
fname = ['time']
4143
for iplt, vplt in enumerate(vfig):
4244
ylabel = None
43-
series_on_plt = (sdat.tseries[tvar] for tvar in vplt)
45+
series_on_plt = [
46+
sdat.tseries.tslice(tvar, conf.time.tstart, conf.time.tend)
47+
for tvar in vplt]
48+
ptstart = min(time[0] for _, time, _ in series_on_plt)
49+
ptend = max(time[-1] for _, time, _ in series_on_plt)
50+
tstart = ptstart if tstart is None else min(ptstart, tstart)
51+
tend = ptend if tend is None else max(ptend, tend)
4452
fname.extend(vplt)
4553
for ivar, (series, time, meta) in enumerate(series_on_plt):
4654
axes[iplt].plot(time, series, conf.time.style,
@@ -69,9 +77,7 @@ def plot_time_series(sdat, lovs):
6977
if unit:
7078
unit = f' ({unit})'
7179
axes[-1].set_xlabel('Time' + unit)
72-
time = sdat.tseries.tslice(
73-
't', conf.time.tstart, conf.time.tend).values
74-
axes[-1].set_xlim(time[[0, -1]])
80+
axes[-1].set_xlim(tstart, tend)
7581
axes[-1].tick_params()
7682
misc.saveplot(fig, '_'.join(fname))
7783

0 commit comments

Comments
 (0)