An error occurred while loading the file. Please try again.
-
Pierre-Antoine Rouby authored065e1f06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# PamhyrPlot.py -- Pamhyr
# Copyright (C) 2023-2024 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 <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
import matplotlib.colors as mplcolors
from matplotlib import ticker
from tools import timestamp_to_old_pamhyr_date
from View.Tools.Plot.APlot import APlot
from View.Tools.Plot.PamhyrCanvas import MplCanvas
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
class PamhyrPlot(APlot):
color_axes = "black"
color_axes_grid = "grey"
color_axes_labels = "black"
color_plot = "red"
color_plot_highlight = "blue"
color_plot_previous = "black"
color_plot_current = "blue"
color_plot_next = "purple"
colors = list(mplcolors.TABLEAU_COLORS)
plot_default_kargs = {
"lw": 1.,
"markersize": 3,
"marker": "+",
}
def __init__(self, data=None,
trad=None, # Translate object
canvas=None, # Use existing canvas
canvas_height=4, canvas_width=5,
canvas_dpi=100,
toolbar=None,
table=None,
parent=None):
if canvas is None:
canvas = MplCanvas(
height=canvas_height, width=canvas_width,
dpi=canvas_dpi
)
self._trad = trad
self._canvas = canvas
self._toolbar = toolbar
self._table = table
self._parent = parent
self._label_x = "X"
self._label_y = "Y"
self._isometric_axis = True
self._auto_relim = True
self._autoscale = True
self._auto_relim_update = False
self._autoscale_update = False
self._highlight_data = None
self._highlight_data_update = False
self._current_data = None
self._current_data_update = False
super(PamhyrPlot, self).__init__(data=data)
@property
def canvas(self):
return self._canvas
@property
def toolbar(self):
return self._toolbar
@property
def table(self):
return self._table
@property
def label_x(self):
return self._label_x
@label_x.setter
def label_x(self, name):
self._label_x = name
@property
def label_y(self):
return self._label_x
@label_y.setter
def label_y(self, name):
self._label_y = name
@property
def highlight(self):
return self._highlight_data
@highlight.setter
def highlight(self, data):
self._highlight_data = data
self._highlight_data_update = True
@property
def current(self):
return self._current_data
@current.setter
def current(self, data):
self._current_data = data
self._current_data_update = True
def init_axes(self):
self.canvas.axes.cla()
self.canvas.axes.grid(
color=self.color_axes_grid,
linestyle='--',
linewidth=0.5
)
self.init_axes_labels()
self.init_axes_axis()
def init_axes_labels(self):
self.canvas.axes.set_xlabel(
self._label_x,
color=self.color_axes_labels,
fontsize=10
)
self.canvas.axes.set_ylabel(
self._label_y,
color=self.color_axes_labels,
fontsize=10
)
def init_axes_axis(self):
if self._isometric_axis:
self.canvas.axes.axis("equal")
else:
self.canvas.axes.axis("tight")
def idle(self):
if self._auto_relim:
self.canvas.axes.relim()
if self._autoscale:
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()
def update_idle(self):
if self._auto_relim_update:
self.canvas.axes.relim()
if self._autoscale_update:
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()
def toolbar_update(self):
if self._toolbar is not None:
self._toolbar.update()
def set_ticks_time_formater(self):
self.canvas.axes.xaxis.set_major_formatter(
lambda x, pos: timestamp_to_old_pamhyr_date(int(x))
)
self.canvas.axes.tick_params(
labelsize=9,
labelrotation=45
)