Skip to content

Commit

Permalink
adjusted the summary_plot to have less blank space
Browse files Browse the repository at this point in the history
  • Loading branch information
cparcerisas committed Jul 6, 2023
1 parent baf96be commit 4d6b204
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 8 additions & 8 deletions pypam/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,23 @@ def plot_summary_dataset(ds, percentiles, data_var='band_density', time_coord='d
[latitude, longitude] in decimal coordinates. If location is passed, a bar with the sun position is going
to be added below the time axis
"""
plt.figure(figsize=(12, 8))
plt.figure(figsize=(12, 7))
gs = gridspec.GridSpec(2, 2, height_ratios=[10, 0.5], width_ratios=[3, 2])

ax0 = plt.subplot(gs[0])
ax1 = plt.subplot(gs[1], sharey=ax0)


# LTSA plot
xarray.plot.pcolormesh(ds[data_var], x=time_coord, y=freq_coord, add_colorbar=True,
cbar_kwargs={'label': '%s [%s]' % ('Spectrum Level', units),
cbar_kwargs={'label': r'%s [$%s$]' % (ds[data_var].standard_name, ds[data_var].units),
'location': 'top', 'orientation': 'horizontal', 'shrink': 2/3}, ax=ax0,
extend='neither', cmap='YlGnBu_r')

# SPD plot
spd = pypam.utils.compute_spd(ds, percentiles=percentiles, min_val=min_val, max_val=max_val)

xarray.plot.pcolormesh(spd['spd'], x='spl', y=freq_coord, cmap='binary', add_colorbar=True,
cbar_kwargs={'label': 'Empirical Probability Density',
cbar_kwargs={'label': r'%s [$%s$]' % (spd['spd'].standard_name, spd['spd'].units),
'location': 'top', 'orientation': 'horizontal'}, ax=ax1,
extend='neither', vmin=0, robust=False)

Expand Down Expand Up @@ -314,19 +313,20 @@ def plot_summary_dataset(ds, percentiles, data_var='band_density', time_coord='d
# Adjust the axis names and visibilities
ax0.set_ylabel('Frequency [Hz]')
ax1.get_yaxis().set_visible(False)
ax1.set_xlabel('Spectrum Level %s' % units)
ax1.set_xlabel(r'%s [$%s$]' % (spd['spl'].standard_name, spd['spl'].units))

if log:
ax0.set_yscale('symlog')

ax1.legend(loc='upper right')
plt.subplots_adjust(wspace=0.05, hspace=0.01)
plt.tight_layout()
if location is not None:
plt.subplots_adjust(wspace=0.05, hspace=0.01)

if save_path is not None:
plt.savefig(save_path)
if show:
plt.show()
if save_path is not None:
plt.savefig(save_path, pad_inches=0.01)


def plot_daily_patterns_from_ds(ds, data_var, interpolate=True, save_path=None, ax=None,
Expand Down
8 changes: 6 additions & 2 deletions tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ def test_summary_plot(self):
# Only necessary while compute_spd not updated
pctlev = [1, 10, 25, 50, 75, 90, 99]
pypam.plots.plot_summary_dataset(ds=self.ds, percentiles=pctlev,
min_val=40, max_val=130, location=[112.186, 36.713], show=True)
min_val=40, max_val=130, location=[112.186, 36.713], show=True,
save_path='tests/test_data/data_exploration/img/data_overview/'
'summary_plot_test1.png')
pypam.plots.plot_summary_dataset(ds=self.ds, percentiles=pctlev,
min_val=40, max_val=130, location=None, show=True)
min_val=40, max_val=130, location=None, show=True,
save_path='tests/test_data/data_exploration/img/data_overview/'
'summary_plot_test2.png')

@skip_unless_with_plots()
def test_plot_daily_patterns_from_ds(self):
Expand Down

0 comments on commit 4d6b204

Please sign in to comment.