diff --git a/src/View/Geometry/PlotKPC.py b/src/View/Geometry/PlotKPC.py index 374b963e2a4d0d9049802ce741f5d4390935a1f4..1bdd98a39c0310723c055d0a4b56921665293ad3 100644 --- a/src/View/Geometry/PlotKPC.py +++ b/src/View/Geometry/PlotKPC.py @@ -10,13 +10,16 @@ from PyQt5.QtCore import ( _translate = QCoreApplication.translate class PlotKPC(APlot): - def __init__(self, canvas=None, data=None, toolbar=None): + def __init__(self, canvas=None, data=None, toolbar=None, + display_current=True): super(PlotKPC, self).__init__( canvas=canvas, data=data, toolbar=toolbar ) + self.display_current = display_current + self.line_kp_zgl = [] self.line_kp_zmin = None self.line_kp_zmin_zmax = None @@ -26,10 +29,13 @@ class PlotKPC(APlot): self.after_plot_selected = None @timer - def draw(self): + def draw(self, highlight=None): self.canvas.axes.cla() self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5) + if self.data is None: + return + if self.data.number_profiles == 0: return @@ -49,29 +55,65 @@ class PlotKPC(APlot): self.line_kp_zmin_zmax = self.canvas.axes.vlines( x=kp, ymin=z_min, ymax=z_max, - color='r', lw=1. + color='r', + lw=1. ) - self.plot_selected, = self.canvas.axes.plot( - (kp[0], kp[0]), - (z_min[0], z_max[0]), - color='b', lw=1.8 - ) - self.plot_selected.set_visible(False) + if highlight is not None: + kp_min, kp_max = highlight - self.before_plot_selected, = self.canvas.axes.plot( - (kp[0], kp[0]), - (z_min[0], z_max[0]), - color='k', lw=1.6, linestyle='--' - ) - self.before_plot_selected.set_visible(False) + indexes = list( + map( + lambda x: x[0], + filter( + lambda x: kp_min <= x[1] <= kp_max, + enumerate(kp) + ) + ) + ) - self.after_plot_selected, = self.canvas.axes.plot( - (kp[0], kp[0]), - (z_min[0], z_max[0]), - color='m', lw=1.6, linestyle='--' - ) - self.after_plot_selected.set_visible(False) + indexes_filter = lambda data: list( + map( + lambda x: x[1], + filter( + lambda x: x[0] in indexes, + enumerate(data) + ) + ) + ) + + ikp = indexes_filter(kp) + imin = indexes_filter(z_min) + imax = indexes_filter(z_max) + + self.line_kp_zmin_zmax = self.canvas.axes.vlines( + x=ikp, + ymin=imin, ymax=imax, + color='b', + lw=1. + ) + + if self.display_current: + self.plot_selected, = self.canvas.axes.plot( + (kp[0], kp[0]), + (z_min[0], z_max[0]), + color='b', lw=1.8 + ) + self.plot_selected.set_visible(False) + + self.before_plot_selected, = self.canvas.axes.plot( + (kp[0], kp[0]), + (z_min[0], z_max[0]), + color='k', lw=1.6, linestyle='--' + ) + self.before_plot_selected.set_visible(False) + + self.after_plot_selected, = self.canvas.axes.plot( + (kp[0], kp[0]), + (z_min[0], z_max[0]), + color='m', lw=1.6, linestyle='--' + ) + self.after_plot_selected.set_visible(False) kp = self.data.get_kp() self.line_kp_zgl = [] @@ -94,7 +136,8 @@ class PlotKPC(APlot): self.canvas.figure.tight_layout() self.canvas.figure.canvas.draw_idle() - self.toolbar.update() + if self.toolbar is not None: + self.toolbar.update() self._init = True diff --git a/src/View/Geometry/PlotXY.py b/src/View/Geometry/PlotXY.py index 4293d8fc3740763ab0d7af3ed417b4f878bbbdac..1aa0d6f050618d95bc3c2b9bae44a89d1a819a2f 100644 --- a/src/View/Geometry/PlotXY.py +++ b/src/View/Geometry/PlotXY.py @@ -106,7 +106,7 @@ class PlotXY(APlot): self.canvas.axes.autoscale_view(True, True, True) self.canvas.axes.autoscale() - self.canvas.figure.tight_layout() + self.canvas.figure.tigth_layout() self.canvas.figure.canvas.draw_idle() self.toolbar.update() diff --git a/src/View/Sections/Window.py b/src/View/Sections/Window.py index 38337f17bd9dc6e649c91566ca5ac386826db68b..e951d245599c75a268d5e301783ed8e811ac19f5 100644 --- a/src/View/Sections/Window.py +++ b/src/View/Sections/Window.py @@ -31,7 +31,7 @@ from View.Sections.Table import ( ) from View.Plot.MplCanvas import MplCanvas -from View.Geometry.PlotXY import PlotXY +from View.Geometry.PlotKPC import PlotKPC from View.Sections.translate import * _translate = QCoreApplication.translate @@ -103,10 +103,11 @@ class SectionsWindow(ASubMainWindow, ListedSubWindow): self.plot_layout = self.find(QVBoxLayout, "verticalLayout") self.plot_layout.addWidget(self.canvas) - self.plot = PlotXY( + self.plot = PlotKPC( canvas = self.canvas, data = None, toolbar = None, + display_current = False ) def setup_connections(self): @@ -156,10 +157,11 @@ class SectionsWindow(ASubMainWindow, ListedSubWindow): sec = self._sections.get(rows[0]) highlight = (sec.begin_kp, sec.end_kp) - self.plot = PlotXY( + self.plot = PlotKPC( canvas = self.canvas, data = data, toolbar = None, + display_current = False ) self.plot.draw(highlight=highlight)