Repository navigation
Expand file tree
/
Copy pathControlMatplotlib.py
More file actions
91 lines (63 loc) · 2.28 KB
/
Copy pathControlMatplotlib.py
File metadata and controls
91 lines (63 loc) · 2.28 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = "Ricardo Ribeiro"
__credits__ = ["Ricardo Ribeiro"]
__license__ = "MIT"
__version__ = "0.0"
__maintainer__ = "Ricardo Ribeiro"
__email__ = "ricardojvr@gmail.com"
__status__ = "Development"
from pyforms.utils.settings_manager import conf
from AnyQt.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout
from pyforms.gui.controls.ControlBase import ControlBase
from AnyQt import _api
if _api.USED_API == _api.QT_API_PYQT5:
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
elif _api.USED_API == _api.QT_API_PYQT4:
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import Axes3D
class ControlMatplotlib(ControlBase, QWidget):
def __init__(self, *args, **kwargs):
QWidget.__init__(self)
ControlBase.__init__(self, *args, **kwargs)
def init_form(self):
self._fig = Figure((5.0, 4.0), dpi=100)
self.canvas = FigureCanvas(self._fig)
self.canvas.setParent(self)
self.mpl_toolbar = NavigationToolbar(self.canvas, self)
vbox = QVBoxLayout()
vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
self.setLayout(vbox)
@property
def value(self): return None
@value.setter
def value(self, value):
self.on_draw = value
self.draw()
def draw(self):
self.on_draw(self._fig)
self.canvas.draw()
def on_draw(self, figure):
""" Redraws the figure
"""
x = range(len(self.value))
#self._axes = self._fig.add_subplot(111)
#self._axes.bar(left=x, height=self.data)
#self.canvas.draw()
axes = figure.add_subplot(111, projection='3d')
axes.clear();
pts = axes.scatter(x, x, x, c=x)
figure.colorbar(pts)
############################################################################
############ Properties ####################################################
############################################################################
@property
def fig(self): return self._fig
@fig.setter
def fig(self, value): self._fig = value
@property
def form(self): return self