-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpl_canvas.py
34 lines (28 loc) · 1.19 KB
/
mpl_canvas.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
import matplotlib
from matplotlib.figure import Figure
# Import Qt and matplotlib modules
try:
from PyQt5.QtWidgets import QSizePolicy
from PyQt5.QtGui import QPalette
matplotlib.use("Qt5Agg")
from matplotlib.backends.backend_qt5agg import (FigureCanvasQTAgg
as FigureCanvas)
except ImportError:
from PyQt4.QtGui import QPalette, QSizePolicy
matplotlib.use("Qt4Agg")
from matplotlib.backends.backend_qt4agg import (FigureCanvasQTAgg
as FigureCanvas)
class MplCanvas(FigureCanvas):
def __init__(self, parent=None):
fig = Figure()
super(MplCanvas, self).__init__(fig)
self.setParent(parent)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.updateGeometry()
def setParent(self, parent):
super(MplCanvas, self).setParent(parent)
if parent:
color = parent.palette().brush(QPalette.Window).color()
self.figure.set_facecolor("#%X%X%X" % (color.red(),
color.green(),
color.blue()))