Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try better user flexibility when creating figures #27

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions glidertest/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,21 @@ def plot_section_with_srss(ds, ax, sel_var='TEMP',start_time = '2023-09-06', end
plt.colorbar(c, label=f'{sel_var} [{ds[sel_var].units}]')
return ax

def check_temporal_drift(ds, ax1, ax2, var='DOXY'):
ax1.scatter(mdates.date2num(ds.TIME),ds[var], s=10)
ax1.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
ax1.set(ylim=(np.nanpercentile(ds[var], 0.01), np.nanpercentile(ds[var], 99.99)), ylabel=var)
def check_temporal_drift(ds: pd.DataFrame, var: str,ax: plt.Axes = None, **kw: dict,)-> tuple({plt.Figure, plt.Axes}):
callumrollo marked this conversation as resolved.
Show resolved Hide resolved
if ax is None:
fig, ax = plt.subplots(1, 2, figsize=(14, 6))
else:
ax = ax
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is ax=ax needed? Seems superfluous

fig = plt.gcf()

ax[0].scatter(mdates.date2num(ds.TIME),ds[var], s=10)
ax[0].xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
ax[0].set(ylim=(np.nanpercentile(ds[var], 0.01), np.nanpercentile(ds[var], 99.99)), ylabel=var)

c=ax2.scatter(ds[var],ds.DEPTH,c=mdates.date2num(ds.TIME), s=10)
ax2.set(xlim=(np.nanpercentile(ds[var], 0.01), np.nanpercentile(ds[var], 99.99)),ylabel='Depth (m)', xlabel=var)
ax2.invert_yaxis()
c=ax[1].scatter(ds[var],ds.DEPTH,c=mdates.date2num(ds.TIME), s=10)
ax[1].set(xlim=(np.nanpercentile(ds[var], 0.01), np.nanpercentile(ds[var], 99.99)),ylabel='Depth (m)', xlabel=var)
ax[1].invert_yaxis()

[a.grid() for a in [ax1, ax2]]
[a.grid() for a in ax]
callumrollo marked this conversation as resolved.
Show resolved Hide resolved
plt.colorbar(c, format=DateFormatter('%b %d'))
return ax1, ax2
return fig, ax
17 changes: 11 additions & 6 deletions notebooks/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 2, figsize=(14, 6))\n",
"tools.check_temporal_drift(ds,ax[0], ax[1], var='CHLA')"
"tools.check_temporal_drift(ds, var='CHLA')"
]
},
{
Expand Down Expand Up @@ -278,8 +277,7 @@
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 2, figsize=(14, 6))\n",
"tools.check_temporal_drift(ds, ax[0], ax[1], var='BBP700')"
"tools.check_temporal_drift(ds, var='BBP700')"
]
},
{
Expand All @@ -301,9 +299,16 @@
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 2, figsize=(14, 6))\n",
"tools.check_temporal_drift(ds, ax[0], ax[1], var='DOXY')"
"tools.check_temporal_drift(ds, var='DOXY')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0bc6bf18-ab77-4446-a8c4-eaecb9460b59",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def test_temporal_drift():
ds = fetchers.load_sample_dataset()
fig, ax = plt.subplots(1, 2)
if 'DOXY' in ds.variables:
tools.check_temporal_drift(ds,ax[0], ax[1], var='DOXY')
tools.check_temporal_drift(ds,'DOXY', ax)
if 'CHLA' in ds.variables:
tools.check_temporal_drift(ds,ax[0], ax[1], var='CHLA')
tools.check_temporal_drift(ds,var='CHLA')