Skip to content

Commit

Permalink
Add year considered as a note instead of xlabel
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsebgosselin committed Apr 27, 2022
1 parent f292ba6 commit 907a267
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions pyhelp/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,23 @@ def plot_area_monthly_avg(self, figname: str = None,
numpoints=1, fontsize=12, frameon=False, borderaxespad=0,
loc='lower left', borderpad=0.5, bbox_to_anchor=(0, 1), ncol=2)

# Setup xlabel.
# Add note about year considered for the hydrologic budget.
masked_years = self.data['years'][mask_years]
year_min = masked_years.min()
year_max = masked_years.max()
if year_min == year_max:
text = f"{year_min:0.0f}"
text = f"Année considérée pour le bilan : {year_min:0.0f}"
else:
text = f"{year_min:0.0f} - {year_max:0.0f}"
ax.set_xlabel(text, fontsize=16, labelpad=10)
text = "Années considérées pour le bilan : "
text += f"{year_min:0.0f} - {year_max:0.0f}"

fig.canvas.draw()
bbox_bottom, _ = ax.xaxis.get_ticklabel_extents(
fig.canvas.get_renderer())
y0 = ax.transAxes.inverted().transform(bbox_bottom)[0][1]
offset = transforms.ScaledTranslation(0, -12/72, fig.dpi_scale_trans)
ax.text(0, y0, text, transform=ax.transAxes + offset,
va='top', ha='left')

fig.tight_layout()

Expand Down Expand Up @@ -369,20 +377,28 @@ def plot_area_yearly_avg(self, figname: str = None,
fontsize=16, labelpad=10)
ax.set_xticklabels([])

# Setup xlabel.
ax.legend(
numpoints=1, fontsize=12, frameon=False, borderaxespad=0,
loc='lower left', borderpad=0.5, bbox_to_anchor=(0, 1, 1, 1),
ncol=2)

# Add note about year considered for the hydrologic budget.
masked_years = self.data['years'][mask_years]
year_min = masked_years.min()
year_max = masked_years.max()
if year_min == year_max:
text = f"{year_min:0.0f}"
text = f"Année considérée pour le bilan : {year_min:0.0f}"
else:
text = f"{year_min:0.0f} - {year_max:0.0f}"
ax.set_xlabel(text, fontsize=16, labelpad=10)
text = "Années considérées pour le bilan : "
text += f"{year_min:0.0f} - {year_max:0.0f}"

ax.legend(
numpoints=1, fontsize=12, frameon=False, borderaxespad=0,
loc='lower left', borderpad=0.5, bbox_to_anchor=(0, 1, 1, 1),
ncol=2)
fig.canvas.draw()
bbox_bottom, _ = ax.xaxis.get_ticklabel_extents(
fig.canvas.get_renderer())
y0 = ax.transAxes.inverted().transform(bbox_bottom)[0][1]
offset = transforms.ScaledTranslation(0, -6/72, fig.dpi_scale_trans)
ax.text(0, y0, text, transform=ax.transAxes + offset,
va='top', ha='left')

fig.tight_layout()

Expand Down

0 comments on commit 907a267

Please sign in to comment.