From 84486c03ed3ec718051ab030a3c1b0712f866e8a Mon Sep 17 00:00:00 2001 From: Theophile Terraz Date: Fri, 24 Oct 2025 15:11:11 +0200 Subject: [PATCH] more work on import data results --- src/View/Results/CustomPlot/Plot.py | 25 +++++------ src/View/Results/CustomPlot/Translate.py | 3 ++ src/View/Results/Window.py | 53 ++++++++++++++++++------ 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/View/Results/CustomPlot/Plot.py b/src/View/Results/CustomPlot/Plot.py index 64e09f66..c1240939 100644 --- a/src/View/Results/CustomPlot/Plot.py +++ b/src/View/Results/CustomPlot/Plot.py @@ -599,13 +599,7 @@ class CustomPlot(PamhyrPlot): self.lines["wet_area"] = line # Legend - lns = reduce( - lambda acc, line: acc + line, - map(lambda line: self.lines[line], self.lines), - [] - ) - labs = list(map(lambda line: self._trad[line], self.lines)) - self.canvas.axes.legend(lns, labs, loc="best") + self.update_legend() def _redraw_rk(self): results = self.data[self._current_res_id] @@ -1103,13 +1097,7 @@ class CustomPlot(PamhyrPlot): self._customize_x_axes_time(ts) # Legend - lns = reduce( - lambda acc, line: acc + line, - map(lambda line: self.lines[line], self.lines), - [] - ) - labs = list(map(lambda line: self._trad[line], self.lines)) - self.canvas.axes.legend(lns, labs, loc="best") + self.update_legend() def _redraw_time(self): @@ -1419,3 +1407,12 @@ class CustomPlot(PamhyrPlot): x = self._timestamp self._current.set_data([x, x], self.canvas.axes.get_ylim()) self.canvas.draw_idle() + + def update_legend(self): + lns = reduce( + lambda acc, line: acc + line, + map(lambda line: self.lines[line], self.lines), + [] + ) + labs = list(map(lambda line: self._trad[line], self.lines)) + self.canvas.axes.legend(lns, labs, loc="best") diff --git a/src/View/Results/CustomPlot/Translate.py b/src/View/Results/CustomPlot/Translate.py index d341732f..a6edcff7 100644 --- a/src/View/Results/CustomPlot/Translate.py +++ b/src/View/Results/CustomPlot/Translate.py @@ -55,6 +55,9 @@ class CustomPlotTranslate(ResultsTranslate): self._dict['wet_perimeter'] = self._dict["unit_wet_perimeter"] self._dict['hydraulic_radius'] = self._dict["unit_hydraulic_radius"] self._dict['froude'] = self._dict["unit_froude"] + self._dict['user_imported'] = _translate( + "CustomPlot", "user_imported" + ) # Unit corresponding long name (plot axes display) diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py index 6e906888..0ef2cbc5 100644 --- a/src/View/Results/Window.py +++ b/src/View/Results/Window.py @@ -19,6 +19,7 @@ import os import csv import logging +from functools import reduce # import rasterio from numpy import sqrt @@ -1268,17 +1269,45 @@ class ResultsWindow(PamhyrWindow): if not ok: return + legend, ok = QInputDialog.getText( + self, 'Legend','Legend:' ) + + if not ok: + return + + if legend.strip() == '': + legend = '*' + + tmp_dict = {'Z': 'water_elevation', + 'Q': 'discharge', + 'x': 'rk', + 't': 'time'} + + tmp_unit = {'Z': ' (m)', + 'Q': ' (m³/s)'} + if data_type == 'Z(x)': - self.canvas_2.axes.scatter(x, y, marker="+") - self.plot_rkc.idle() + line = self.canvas_2.axes.plot(x, y, marker="+", + label = legend + ' (m)') + self.plot_rkc.canvas.draw_idle() + self.plot_rkc.update_idle() if data_type == 'Q(t)': - self.canvas_4.axes.scatter(x, y, marker="+") - self.plot_h.idle() - if data_type == 'Z(t)': - for plot in self._additional_plot: - x_key = plot.split(": ")[0] - y_key = plot.split(": ")[1].split(",") - if 'time' in x_key and 'water_elevation' in y_key: - self._additional_plot[plot].canvas.axes.scatter( - x, y, marker="+") - self._additional_plot[plot].idle() + line = self.canvas_4.axes.plot(x, y, + marker="+", + label = legend + ' (m³/s)') + self.plot_h._line.append(line) + self.plot_h.enable_legend() + for p in self._additional_plot: + plot = self._additional_plot[p] + x_key = p.split(": ")[0] + y_key = p.split(": ")[1].split(",") + if (tmp_dict[data_type[2]] in x_key and + tmp_dict[data_type[0]] in y_key): + while legend in plot.lines: + legend += '*' + plot._trad._dict[legend] = legend + tmp_unit[data_type[0]] + plot.lines[legend] = plot.canvas.axes.plot(x, y, + marker="+", + linestyle="--") + plot.update_legend() + plot.idle()