more work on import data results

scenarios
Theophile Terraz 2025-10-24 15:11:11 +02:00
parent 68b62a5630
commit 84486c03ed
3 changed files with 55 additions and 26 deletions

View File

@ -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")

View File

@ -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)

View File

@ -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()