-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatplotlib_window.py
58 lines (41 loc) · 1.67 KB
/
matplotlib_window.py
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
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from PyQt5 import QtCore, QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class MatplotlibPlot(FigureCanvas):
def __init__(self, parent=None, width=1, height=1, dpi=1000):
self.fig = Figure(figsize=(width, height), dpi=dpi)
FigureCanvas.__init__(self, self.fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
def compute_initial_figure(self):
pass
class ResiduePlot(MatplotlibPlot):
def __init__(self):
super().__init__()
def compute_initial_figure(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)
self.axes.plot(t, s)
class MyDynamicMplCanvas(MatplotlibPlot):
def __init__(self, *args, **kwargs):
MatplotlibPlot.__init__(self, *args, **kwargs)
self.axes = self.fig.add_subplot(111, projection='3d')
self.colorbar_exists = False
def update_plot(self, data):
dim_x, dim_y, dim_z = data.shape
XX, YY, ZZ = np.mgrid[:dim_x, :dim_y, :dim_z]
self.axes.cla()
plot = self.axes.scatter(XX.ravel(),
YY.ravel(),
ZZ.ravel(),
c=data.ravel(),
cmap=plt.hot())
if not self.colorbar_exists:
self.colorbar_exists = True
self.fig.colorbar(plot)
self.draw()