Skip to content

Commit

Permalink
Adjusted dates / size on plot_quench_asses
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorfrajka committed Nov 20, 2024
1 parent ef0bd02 commit f56c9e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 19 additions & 0 deletions glidertest/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def plot_quench_assess(ds: xr.Dataset, sel_var: str, ax: plt.Axes = None, start_
with plt.style.context(glidertest_style_file):
if ax is None:
fig, ax = plt.subplots()
full_width = fig.get_size_inches()[0]
fig.set_size_inches(full_width, full_width * 0.5)
else:
fig = plt.gcf()

Expand All @@ -325,6 +327,9 @@ def plot_quench_assess(ds: xr.Dataset, sel_var: str, ax: plt.Axes = None, start_
ds_sel = ds.sel(TIME=slice(t1,t2))
else:
ds_sel = ds.sel(TIME=slice(start_time, end_time))
start_time = ds_sel.TIME.min().values
end_time = ds_sel.TIME.max().values


if len(ds_sel.TIME) == 0:
msg = f"supplied limits start_time: {start_time} end_time: {end_time} do not overlap with dataset TIME range {str(ds.TIME.values.min())[:10]} - {str(ds.TIME.values.max())[:10]}"
Expand All @@ -340,6 +345,20 @@ def plot_quench_assess(ds: xr.Dataset, sel_var: str, ax: plt.Axes = None, start_
for m in np.unique(sunrise):
ax.axvline(np.unique(m), c='orange')
ax.set_ylabel('Depth [m]')

# Set x-tick labels based on duration of the selection
# Could pop out as a utility plotting function?
if (end_time - start_time) < np.timedelta64(1, 'D'):
ax.xaxis.set_major_formatter(DateFormatter('%H:%M'))
start_date = pd.to_datetime(start_time).strftime('%Y-%b-%d')
end_date = pd.to_datetime(end_time).strftime('%Y-%b-%d')
if start_date==end_date:
ax.set_xlabel(f'Time [UTC] ({start_date})')
else:
ax.set_xlabel(f'Time [UTC] ({start_date} to {end_date})')
else:
ax.xaxis.set_major_formatter(DateFormatter('%d-%b'))

plt.colorbar(c, label=f'{sel_var} [{ds[sel_var].units}]')
plt.show()
return fig, ax
Expand Down
8 changes: 3 additions & 5 deletions notebooks/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@
"outputs": [],
"source": [
"# Let's visually check a section of chlorphyll and see if we observe any NPQ\n",
"fig, ax = plt.subplots(1, 1, figsize=(15, 5))\n",
"\n",
"plots.plot_quench_assess(ds, 'CHLA', ax, ylim=35);"
"plots.plot_quench_assess(ds, 'CHLA', ax=None, ylim=35);"
]
},
{
Expand Down Expand Up @@ -478,7 +476,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -492,7 +490,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down

0 comments on commit f56c9e1

Please sign in to comment.