diff --git a/src/View/Results/CustomPlot/Plot.py b/src/View/Results/CustomPlot/Plot.py index b0107a1d77f6dc4eb98bebdc2c7043b5567b88ff..e8a21d955e880fe27303f1b7a3ec6b4fe4826fad 100644 --- a/src/View/Results/CustomPlot/Plot.py +++ b/src/View/Results/CustomPlot/Plot.py @@ -90,33 +90,21 @@ class CustomPlot(PamhyrPlot): ) ) - # self.canvas.axes.set_xlim( - # left=min(rk), right=max(rk) - # ) - - meter_axes = self.canvas.axes - #m3s_axes = meter_axes.twinx() - #ms_axes = meter_axes.twinx() shift = 0 - if "0-meter" in self._y_axes and "1-m3s" in self._y_axes: - m3s_axes = self._axes["1-m3s"] - m3s_axes.spines['right'].set_position(('outward', shift)) - shift += 60 - - if "0-meter" in self._y_axes and "2-ms" in self._y_axes: - ms_axes = self._axes["2-ms"] - ms_axes.spines['right'].set_position(('outward', shift)) - shift += 60 + compt = 0 + for ax in sorted(self._axes): + if compt == 0: + self._axes[ax].spines['left'].set_position(('outward', shift)) + compt += 1 + else: + self._axes[ax].spines['right'].set_position(('outward', shift)) + shift += 60 lines = {} if "elevation" in self._y: - # meter_axes.set_ylim( - # bottom=min(0, min(z_min)), - # top=max(z_min) + 1 - # ) - - line = meter_axes.plot( + ax = self._axes[unit["elevation"]] + line = ax.plot( rk, z_min, color='grey', lw=1., ) @@ -124,37 +112,31 @@ class CustomPlot(PamhyrPlot): if "water_elevation" in self._y: - # meter_axes.set_ylim( - # bottom=min(0, min(z_min)), - # top=max(z) + 1 - # ) - - line = meter_axes.plot( + ax = self._axes[unit["water_elevation"]] + line = ax.plot( rk, z, lw=1., color='blue', ) lines["water_elevation"] = line if "elevation" in self._y: - meter_axes.fill_between( + ax.fill_between( rk, z_min, z, color='blue', alpha=0.5, interpolate=True ) if "discharge" in self._y: - # m3s_axes.set_ylim( - # bottom=min(0, min(q)), - # top=max(q) + 1 - # ) - - line = m3s_axes.plot( + ax = self._axes[unit["discharge"]] + line = ax.plot( rk, q, lw=1., color='r', ) lines["discharge"] = line if "velocity" in self._y: + + ax = self._axes[unit["velocity"]] v = list( map( lambda p: p.geometry.speed( @@ -164,12 +146,7 @@ class CustomPlot(PamhyrPlot): ) ) - # m3s_axes.set_ylim( - # bottom=min(0, min(q)), - # top=max(q) + 1 - # ) - - line = ms_axes.plot( + line = ax.plot( rk, v, lw=1., color='g', ) @@ -229,19 +206,15 @@ class CustomPlot(PamhyrPlot): reach = results.river.reach(self._reach) profile = reach.profile(self._profile) - meter_axes = self.canvas.axes - #m3s_axes = meter_axes.twinx() - #ms_axes = meter_axes.twinx() shift = 0 - if "0-meter" in self._y_axes and "1-m3s" in self._y_axes: - m3s_axes = self._axes["1-m3s"] - m3s_axes.spines['right'].set_position(('outward', shift)) - shift += 60 - - if "0-meter" in self._y_axes and "2-ms" in self._y_axes: - ms_axes = self._axes["2-ms"] - ms_axes.spines['right'].set_position(('outward', shift)) - shift += 60 + compt = 0 + for ax in sorted(self._axes): + if compt == 0: + self._axes[ax].spines['left'].set_position(('outward', shift)) + compt += 1 + else: + self._axes[ax].spines['right'].set_position(('outward', shift)) + shift += 60 ts = list(results.get("timestamps")) ts.sort() @@ -249,14 +222,11 @@ class CustomPlot(PamhyrPlot): q = profile.get_key("Q") z = profile.get_key("Z") - # self.canvas.axes.set_xlim( - # left=min(ts), right=max(ts) - # ) - - x = ts lines = {} if "elevation" in self._y: # Z min is constant in time + + ax = self._axes[unit["elevation"]] z_min = profile.geometry.z_min() ts_z_min = list( map( @@ -265,7 +235,7 @@ class CustomPlot(PamhyrPlot): ) ) - line = meter_axes.plot( + line = ax.plot( ts, ts_z_min, color='grey', lw=1. ) @@ -273,12 +243,8 @@ class CustomPlot(PamhyrPlot): if "water_elevation" in self._y: - # meter_axes.set_ylim( - # bottom=min(0, min(z)), - # top=max(z) + 1 - # ) - - line = meter_axes.plot( + ax = self._axes[unit["water_elevation"]] + line = ax.plot( ts, z, lw=1., color='b', ) @@ -293,19 +259,15 @@ class CustomPlot(PamhyrPlot): ) ) - meter_axes.fill_between( + ax.fill_between( ts, ts_z_min, z, color='blue', alpha=0.5, interpolate=True ) if "discharge" in self._y: - # m3s_axes.set_ylim( - # bottom=min(0, min(q)), - # top=max(q) + 1 - # ) - - line = m3s_axes.plot( + ax = self._axes[unit["discharge"]] + line = ax.plot( ts, q, lw=1., color='r', ) @@ -313,6 +275,7 @@ class CustomPlot(PamhyrPlot): if "velocity" in self._y: + ax = self._axes[unit["velocity"]] v = list( map( lambda q, z: profile.geometry.speed(q, z), @@ -320,12 +283,7 @@ class CustomPlot(PamhyrPlot): ) ) - # ms_axes.set_ylim( - # bottom=min(0, min(q)), - # top=max(q) + 1 - # ) - - line = ms_axes.plot( + line = ax.plot( ts, v, lw=1., color='g', ) @@ -360,6 +318,7 @@ class CustomPlot(PamhyrPlot): color='black', fontsize=10 ) + self._axes[self._y_axes[0]] = self.canvas.axes for axes in self._y_axes[1:]: if axes in self._axes: self._axes[axes].clear() @@ -377,7 +336,6 @@ class CustomPlot(PamhyrPlot): elif self._x == "time": self._draw_time() - #self.canvas.figure.tight_layout() self.canvas.figure.canvas.draw_idle() if self.toolbar is not None: self.toolbar.update() diff --git a/src/View/Results/CustomPlot/Translate.py b/src/View/Results/CustomPlot/Translate.py index ebbea20a629d816dc17de205d7cca2ccb5e87a06..5e9944c7502debe33777770487af02c59ae3bf84 100644 --- a/src/View/Results/CustomPlot/Translate.py +++ b/src/View/Results/CustomPlot/Translate.py @@ -41,6 +41,12 @@ class CustomPlotTranslate(ResultsTranslate): "CustomPlot", "Bed elevation (m)" ) self._dict['velocity'] = self._dict["unit_speed"] + self._dict['width'] = self._dict["unit_width"], + self._dict['max_depth'] = self._dict["unit_max_height"], + self._dict['mean_depth'] = self._dict["unit_mean_height"], + self._dict['wet_area'] = self._dict["unit_wet_area"], + self._dict['wet_perimeter'] = self._dict["unit_wet_perimeter"], + self._dict['hydraulic_radius'] = self._dict["unit_hydraulic_radius"], # Unit corresponding long name (plot axes display) diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py index 3577b21aac5ad93a43cb6d228f90d7ada33934fa..dc47d0a5a01e03d466bace8ce0503b17777e6cac 100644 --- a/src/View/Results/Window.py +++ b/src/View/Results/Window.py @@ -507,7 +507,7 @@ class ResultsWindow(PamhyrWindow): tab_widget = self.find(QTabWidget, f"tabWidget") # This plot already exists - if name in self._additional_plot: + if name in [tab_widget.tabText(i) for i in range(tab_widget.count())]: tab_widget.setCurrentWidget( tab_widget.findChild(QWidget, wname) ) @@ -536,9 +536,6 @@ class ResultsWindow(PamhyrWindow): ) plot.draw() - # Add plot to additional plot - self._additional_plot[name] = plot - grid.addWidget(toolbar, 0, 0) grid.addWidget(canvas, 1, 0) widget.setLayout(grid)