# Plot.py -- Pamhyr # Copyright (C) 2023 INRAE # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -*- coding: utf-8 -*- import logging from datetime import datetime from tools import timer, trace from View.Tools.PamhyrPlot import PamhyrPlot from PyQt5.QtCore import ( QCoreApplication ) from View.BoundaryCondition.Edit.translate import BCETranslate _translate = QCoreApplication.translate logger = logging.getLogger() class Plot(PamhyrPlot): def __init__(self, mode="time", data=None, trad=None, canvas=None, toolbar=None, parent=None): super(Plot, self).__init__( canvas=canvas, trad=trad, data=data, toolbar=toolbar, parent=parent ) self._table_headers = self._trad.get_dict("table_headers") self._mode = mode @timer def draw(self): self.canvas.axes.cla() self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5) if len(self.data) == 0: self._init = False return # Plot data x = list(map(lambda v: v[0], self.data.data)) y = list(map(lambda v: v[1], self.data.data)) self._line, = self.canvas.axes.plot( x, y, color='r', lw=1., markersize=5, marker='+', picker=30, ) # Plot label # header = self.data.header self.canvas.axes.set_xlabel( self._table_headers["z"], color='black', fontsize=10 ) self.canvas.axes.set_ylabel( self._table_headers["Area"], color='black', fontsize=10 ) self.canvas.axes.autoscale_view(True, True, True) self.canvas.figure.tight_layout() self.canvas.figure.canvas.draw_idle() # self.toolbar.update() self._init = True @timer def update(self, ind=None): if not self._init: self.draw() return x = list(map(lambda v: v[0], self.data.data)) y = list(map(lambda v: v[1], self.data.data)) self._line.set_data(x, y) self.canvas.axes.relim() self.canvas.axes.autoscale() self.canvas.figure.tight_layout() self.canvas.figure.canvas.draw_idle()