mirror of https://gitlab.com/pamhyr/pamhyr2
work on custom plots
parent
12cca24d8b
commit
f96f9cc62f
|
|
@ -32,6 +32,7 @@ unit = {
|
|||
"elevation": "0-meter",
|
||||
"water_elevation": "0-meter",
|
||||
"discharge": "1-m3s",
|
||||
"velocity": "2-ms",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -76,18 +77,40 @@ class CustomPlot(PamhyrPlot):
|
|||
reach = results.river.reach(self._reach)
|
||||
rk = reach.geometry.get_rk()
|
||||
z_min = reach.geometry.get_z_min()
|
||||
q = list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(self._timestamp, "Q"),
|
||||
reach.profiles
|
||||
)
|
||||
)
|
||||
z = list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(self._timestamp, "Z"),
|
||||
reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
# self.canvas.axes.set_xlim(
|
||||
# left=min(rk), right=max(rk)
|
||||
# )
|
||||
|
||||
meter_axes = self.canvas.axes
|
||||
m3S_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
|
||||
|
||||
lines = {}
|
||||
if "elevation" in self._y:
|
||||
|
||||
# meter_axes.set_ylim(
|
||||
# bottom=min(0, min(z_min)),
|
||||
# top=max(z_min) + 1
|
||||
|
|
@ -100,38 +123,25 @@ class CustomPlot(PamhyrPlot):
|
|||
lines["elevation"] = line
|
||||
|
||||
if "water_elevation" in self._y:
|
||||
# Water elevation
|
||||
water_z = list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(self._timestamp, "Z"),
|
||||
reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
# meter_axes.set_ylim(
|
||||
# bottom=min(0, min(z_min)),
|
||||
# top=max(water_z) + 1
|
||||
# top=max(z) + 1
|
||||
# )
|
||||
|
||||
line = meter_axes.plot(
|
||||
rk, water_z, lw=1.,
|
||||
rk, z, lw=1.,
|
||||
color='blue',
|
||||
)
|
||||
lines["water_elevation"] = line
|
||||
|
||||
if "elevation" in self._y:
|
||||
meter_axes.fill_between(
|
||||
rk, z_min, water_z,
|
||||
rk, z_min, z,
|
||||
color='blue', alpha=0.5, interpolate=True
|
||||
)
|
||||
|
||||
if "discharge" in self._y:
|
||||
q = list(
|
||||
map(
|
||||
lambda p: p.get_ts_key(self._timestamp, "Q"),
|
||||
reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
# m3s_axes.set_ylim(
|
||||
# bottom=min(0, min(q)),
|
||||
|
|
@ -144,6 +154,27 @@ class CustomPlot(PamhyrPlot):
|
|||
)
|
||||
lines["discharge"] = line
|
||||
|
||||
if "velocity" in self._y:
|
||||
v = list(
|
||||
map(
|
||||
lambda p: p.geometry.speed(
|
||||
p.get_ts_key(self._timestamp, "Q"),
|
||||
p.get_ts_key(self._timestamp, "Z")),
|
||||
reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
# m3s_axes.set_ylim(
|
||||
# bottom=min(0, min(q)),
|
||||
# top=max(q) + 1
|
||||
# )
|
||||
|
||||
line = ms_axes.plot(
|
||||
rk, v, lw=1.,
|
||||
color='g',
|
||||
)
|
||||
lines["velocity"] = line
|
||||
|
||||
# Legend
|
||||
lns = reduce(
|
||||
lambda acc, line: acc + line,
|
||||
|
|
@ -151,7 +182,7 @@ class CustomPlot(PamhyrPlot):
|
|||
[]
|
||||
)
|
||||
labs = list(map(lambda line: self._trad[line], lines))
|
||||
self.canvas.axes.legend(lns, labs, loc="lower left")
|
||||
self.canvas.axes.legend(lns, labs, loc="best")
|
||||
|
||||
def _customize_x_axes_time(self, ts, mode="time"):
|
||||
# Custom time display
|
||||
|
|
@ -199,13 +230,25 @@ class CustomPlot(PamhyrPlot):
|
|||
profile = reach.profile(self._profile)
|
||||
|
||||
meter_axes = self.canvas.axes
|
||||
m3S_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
|
||||
|
||||
ts = list(results.get("timestamps"))
|
||||
ts.sort()
|
||||
|
||||
q = profile.get_key("Q")
|
||||
z = profile.get_key("Z")
|
||||
|
||||
# self.canvas.axes.set_xlim(
|
||||
# left=min(ts), right=max(ts)
|
||||
# )
|
||||
|
|
@ -229,8 +272,6 @@ class CustomPlot(PamhyrPlot):
|
|||
lines["elevation"] = line
|
||||
|
||||
if "water_elevation" in self._y:
|
||||
# Water elevation
|
||||
z = profile.get_key("Z")
|
||||
|
||||
# meter_axes.set_ylim(
|
||||
# bottom=min(0, min(z)),
|
||||
|
|
@ -258,7 +299,6 @@ class CustomPlot(PamhyrPlot):
|
|||
)
|
||||
|
||||
if "discharge" in self._y:
|
||||
q = profile.get_key("Q")
|
||||
|
||||
# m3s_axes.set_ylim(
|
||||
# bottom=min(0, min(q)),
|
||||
|
|
@ -271,6 +311,26 @@ class CustomPlot(PamhyrPlot):
|
|||
)
|
||||
lines["discharge"] = line
|
||||
|
||||
if "velocity" in self._y:
|
||||
|
||||
v = list(
|
||||
map(
|
||||
lambda q, z: profile.geometry.speed(q, z),
|
||||
q, z
|
||||
)
|
||||
)
|
||||
|
||||
# ms_axes.set_ylim(
|
||||
# bottom=min(0, min(q)),
|
||||
# top=max(q) + 1
|
||||
# )
|
||||
|
||||
line = ms_axes.plot(
|
||||
ts, v, lw=1.,
|
||||
color='g',
|
||||
)
|
||||
lines["velocity"] = line
|
||||
|
||||
self._customize_x_axes_time(ts)
|
||||
|
||||
# Legend
|
||||
|
|
@ -280,7 +340,7 @@ class CustomPlot(PamhyrPlot):
|
|||
[]
|
||||
)
|
||||
labs = list(map(lambda line: self._trad[line], lines))
|
||||
self.canvas.axes.legend(lns, labs, loc="lower left")
|
||||
self.canvas.axes.legend(lns, labs, loc="best")
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
|
|
@ -317,7 +377,7 @@ class CustomPlot(PamhyrPlot):
|
|||
elif self._x == "time":
|
||||
self._draw_time()
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
#self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
if self.toolbar is not None:
|
||||
self.toolbar.update()
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ class CustomPlotTranslate(ResultsTranslate):
|
|||
self._dict['elevation'] = _translate(
|
||||
"CustomPlot", "Bed elevation (m)"
|
||||
)
|
||||
self._dict['velocity'] = self._dict["unit_speed"]
|
||||
|
||||
# Unit corresponding long name (plot axes display)
|
||||
|
||||
|
|
@ -47,6 +48,7 @@ class CustomPlotTranslate(ResultsTranslate):
|
|||
"CustomPlot", "Bed elevation (m)"
|
||||
)
|
||||
self._dict['1-m3s'] = self._dict["unit_discharge"]
|
||||
self._dict['2-ms'] = self._dict["unit_speed"]
|
||||
|
||||
# SubDict
|
||||
|
||||
|
|
@ -58,4 +60,5 @@ class CustomPlotTranslate(ResultsTranslate):
|
|||
"elevation": self._dict["elevation"],
|
||||
"water_elevation": self._dict["water_elevation"],
|
||||
"discharge": self._dict["discharge"],
|
||||
"velocity": self._dict["velocity"],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ from PyQt5.QtWidgets import (
|
|||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||
QSlider, QLabel, QWidget, QGridLayout,
|
||||
QSlider, QLabel, QWidget, QGridLayout, QTabBar
|
||||
)
|
||||
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
|
|
@ -158,6 +158,12 @@ class ResultsWindow(PamhyrWindow):
|
|||
|
||||
def setup_plots(self):
|
||||
self.canvas = MplCanvas(width=5, height=4, dpi=100)
|
||||
tab_widget = self.find(QTabWidget, f"tabWidget")
|
||||
tab_widget.setTabsClosable(True)
|
||||
tab_widget.tabCloseRequested.connect(self.delete_tab)
|
||||
tab_widget.tabBar().setTabButton(0, QTabBar.RightSide, None)
|
||||
tab_widget.tabBar().setTabButton(1, QTabBar.RightSide, None)
|
||||
tab_widget.tabBar().setTabButton(2, QTabBar.RightSide, None)
|
||||
self.canvas.setObjectName("canvas")
|
||||
self.toolbar = PamhyrPlotToolbar(
|
||||
self.canvas, self, items=[
|
||||
|
|
@ -661,3 +667,7 @@ class ResultsWindow(PamhyrWindow):
|
|||
def export_current_to(self, directory):
|
||||
reach = self._results.river.reachs[self._get_current_reach()]
|
||||
self.export_reach(reach, directory, [self._get_current_timestamp()])
|
||||
|
||||
def delete_tab(self, index):
|
||||
tab_widget = self.find(QTabWidget, f"tabWidget")
|
||||
tab_widget.removeTab(index)
|
||||
|
|
|
|||
|
|
@ -192,7 +192,6 @@ class PamhyrPlot(APlot):
|
|||
self.canvas.axes.autoscale_view(True, True, True)
|
||||
self.canvas.axes.autoscale()
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
|
||||
self.toolbar_update()
|
||||
|
|
@ -205,7 +204,6 @@ class PamhyrPlot(APlot):
|
|||
self.canvas.axes.autoscale_view(True, True, True)
|
||||
self.canvas.axes.autoscale()
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
|
||||
self.toolbar_update()
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class MplCanvas(FigureCanvasQTAgg):
|
|||
fig = Figure(
|
||||
figsize=(width, height),
|
||||
dpi=dpi,
|
||||
layout='tight',
|
||||
layout='constrained',
|
||||
)
|
||||
super(MplCanvas, self).__init__(fig)
|
||||
|
||||
|
|
@ -36,7 +36,6 @@ class MplCanvas(FigureCanvasQTAgg):
|
|||
self.axes.yaxis.tick_left()
|
||||
self.axes.xaxis.tick_bottom()
|
||||
self.axes.spines[['top', 'right']].set_color('none')
|
||||
self.figure.tight_layout()
|
||||
self.add_arrows()
|
||||
|
||||
def add_arrows(self):
|
||||
|
|
|
|||
|
|
@ -145,7 +145,10 @@
|
|||
<item row="0" column="0">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="tabsClosable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
|
|
|
|||
Loading…
Reference in New Issue