From f9a099a284b907bbace289ed244b0893f606a42a Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Mon, 19 Feb 2024 09:46:43 +0100 Subject: [PATCH] Results: Hydrograph: Add legend. --- src/View/Results/PlotH.py | 9 +++++++++ src/View/Tools/PamhyrPlot.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/View/Results/PlotH.py b/src/View/Results/PlotH.py index 2a626a36..2b33f48c 100644 --- a/src/View/Results/PlotH.py +++ b/src/View/Results/PlotH.py @@ -54,6 +54,10 @@ class PlotH(PamhyrPlot): self.label_x = _translate("Results", "Time (s)") self.label_y = _translate("Results", "Discharge (m³/s)") + self.label_discharge = _translate("Results", "Cross-section discharge") + self.label_discharge_max = _translate("Results", "Max discharge") + self.label_timestamp = _translate("Results", "Current timestamp") + self._isometric_axis = False self._auto_relim_update = True @@ -88,6 +92,8 @@ class PlotH(PamhyrPlot): self.set_ticks_time_formater() + self.enable_legend() + self.idle() self._init = True @@ -100,6 +106,7 @@ class PlotH(PamhyrPlot): self._line, = self.canvas.axes.plot( x, y, + label=self.label_discharge, color=self.color_plot, **self.plot_default_kargs ) @@ -112,6 +119,7 @@ class PlotH(PamhyrPlot): self._current, = self.canvas.axes.plot( self._current_timestamp, y[self.ts.index(self._current_timestamp)], + # label=self.label_timestamp, color=self.color_plot_current, **kargs ) @@ -131,6 +139,7 @@ class PlotH(PamhyrPlot): self._line_max, = self.canvas.axes.plot( x, y, + label=self.label_discharge_max, color=self.color_plot_highlight, linestyle='dotted', **self.plot_default_kargs diff --git a/src/View/Tools/PamhyrPlot.py b/src/View/Tools/PamhyrPlot.py index df11dfdb..309c4b7b 100644 --- a/src/View/Tools/PamhyrPlot.py +++ b/src/View/Tools/PamhyrPlot.py @@ -200,3 +200,10 @@ class PamhyrPlot(APlot): labelsize=9, labelrotation=45 ) + + def enable_legend(self): + self.canvas.axes.legend( + fancybox=True, + shadow=True, + fontsize=8 + ) -- GitLab