本文整理汇总了Python中matplotlib.backends.backend_qt4agg.NavigationToolbar2QT.setParent方法的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QT.setParent方法的具体用法?Python NavigationToolbar2QT.setParent怎么用?Python NavigationToolbar2QT.setParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.NavigationToolbar2QT
的用法示例。
在下文中一共展示了NavigationToolbar2QT.setParent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mGraph
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QT import setParent [as 别名]
class mGraph(QtGui.QWidget):
def __init__(self, device, parent=None):
QtGui.QWidget.__init__(self, parent)
# Create a matplotlib figure
self.figure = plt.figure()
self.figure.set_facecolor("r")
# Create a QFrame to house the plot. This is not necessary, just makes it look nice
self.matframe = QtGui.QFrame()
self.matLayout = QtGui.QVBoxLayout()
self.matLayout.setSpacing(0)
self.matframe.setLayout(self.matLayout)
self.matframe.setFrameShape(QtGui.QFrame.Panel)
self.matframe.setFrameShadow(QtGui.QFrame.Plain)
self.matframe.setStyleSheet("background-color: rgb(70,80,88); margin:0px; border:2px solid rgb(0, 0, 0); ")
self.canvas = FigureCanvas(self.figure)
self.canvas.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
# This is the device we want to use
self.device = device
# This sets up axis on which to plot
self.ax = self.figure.add_subplot(111, axisbg=(189.0 / 255, 195.0 / 255, 199.0 / 255))
# Add the matplotlib canvas to the QFrame
self.matLayout.addWidget(self.canvas)
# The following lines set up all the colors, makes it look nice. The code to do it is
# far from pretty and I am planning on cleaning this up a bit.
self.figure.patch.set_color((70.0 / 255, 80.0 / 255, 88.0 / 255))
self.figure.patch.set_edgecolor((70.0 / 255, 80.0 / 255, 88.0 / 255))
self.ax.spines["bottom"].set_color((189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.spines["top"].set_color((189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.spines["right"].set_color((189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.spines["left"].set_color((189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.tick_params(axis="x", colors=(189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.tick_params(axis="y", colors=(189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.title.set_color((189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.yaxis.label.set_color((189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.xaxis.label.set_color((189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.xaxis.get_offset_text().set_color((189.0 / 255, 195.0 / 255, 199.0 / 255))
self.ax.yaxis.get_offset_text().set_color((189.0 / 255, 195.0 / 255, 199.0 / 255))
# This is an array of all the lines on the plot. A line for every parameter
self.line = []
# Each element of line holds a plot, to be combined onto the same graph
self.line.append(self.ax.plot(1, 1, label="Getting Data...")[0])
# This is the ONLY time canvas.draw is called. It should NOT be called anywhere else if
# the graphing speed is to be fast.
self.canvas.draw()
# In order to handle interactivity, I had to do some odd stuff with the
# toolbar buttons. Self.home holds the original function called when the home button on the toolbar
# is clicked.
self.home = NavigationToolbar.home
# We now change the function that is called when the toolbar is clicked.
NavigationToolbar.home = self.enableAutoScaling
self.toolbar = NavigationToolbar(self.canvas, self)
# print [item for item in dir(self.toolbar) if type(item) == QtGui.QDialog]
self.cid = self.canvas.mpl_connect("button_press_event", self.disableAutoScaling)
self.setStyleSheet(
"QPushButton{\
color:rgb(189,195, 199); \
background:rgb(70, 80, 88)}"
)
self.toolbarFrame = QtGui.QFrame()
toolbarFrameLayout = QtGui.QVBoxLayout()
toolbarFrameLayout.addWidget(self.toolbar)
self.toolbar.setParent(None)
self.toolbarFrame.setLayout(toolbarFrameLayout)
self.toolbarFrame.setStyleSheet(
"\
border:2px solid rgb(0,0,0);\
color:rgb(189,195,199); \
background:rgb(70, 80, 88);\
"
)
self.toolbar.setStyleSheet(
"\
border:0px solid rgb(0,0,0);\
QDialog{background:rgb(250, 80, 88)}\
"
)
# print dir(self.toolbar)
# print self.toolbar.children()
# print self.toolbar.setPalette
self.matPlotInfo = QtGui.QLabel()
self.alertFont = QtGui.QFont()
self.alertFont.setPointSize(12)
self.matPlotInfo.setStyleSheet("color:rgb(200, 69, 50);")
self.matPlotInfo.setText("Auto refresh disabled, click HOME button to enable.")
self.matPlotInfo.setFont(self.alertFont)
self.refreshRateSec = device.getFrame().getPlotRefreshRate()
self.timer = QtCore.QTimer(self)
self.hidden = True
self.home = True
self.currTimeRange = 120
self.plot(self.currTimeRange)
self.timer.timeout.connect(partial(self.plot, self.currTimeRange))
self.timer.start(self.refreshRateSec * 1000)
# did it store data?
self.dataOk = True
self.hideButton = QtGui.QPushButton("Show Plot")
self.hideButton.clicked.connect(self.togglePlot)
#.........这里部分代码省略.........
示例2: Window
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QT import setParent [as 别名]
#.........这里部分代码省略.........
self.splitter1.addWidget(self.candlestick)
#self.splitter1.addWidget(self.rsiGraph)
self.splitter1.addWidget(self.toolbar)
self.graphVBox.addWidget(self.splitter1)
self.mainHBox.addLayout(self.leftVBox)
self.mainHBox.addLayout(self.graphVBox)
self.main_widget.setFocus()
#self.side_widget.setFocus()
self.setCentralWidget(self.main_widget)
#search = self.searchInput()
#self.fig = plt.figure()
#graph = FigureCanvas(self.fig)
#vbox = QtGui.QVBoxLayout()
#hbox = QtGui.QHBoxLayout()
#self.ani = FuncAnimation(graph.figure, self.animate, interval=2000)
#self.rsiGraph.hide()
self.show()
"""
runs when the search Button is clicked
"""
def searchBtn_clicked(self):
global stock
stock = self.search.text().upper()
self.search.clear()
self.stockLabel.setText(stock)
print(stock)
self.candlestick.setParent(None)
self.toolbar.setParent(None)
self.splitter1.setParent(None)
self.candlestick = mainGraphCanvas(self.main_widget)
self.toolbar = NavigationToolbar(self.candlestick, self.main_widget)
self.splitter1 = QtGui.QSplitter(QtCore.Qt.Vertical)
self.splitter1.addWidget(self.candlestick)
self.splitter1.addWidget(self.toolbar)
self.graphVBox.addWidget(self.splitter1)
if indicatorRSI == True:
self.rsiGraph = rsiGraphCanvas(self.main_widget)
self.splitter1.addWidget(self.rsiGraph)
self.rsi.show()
"""
runs when one of the intervals is clicked
"""
def onActivated(self, text):
global interval
if text == "Daily":
interval = "1d"
if text == "3 Days":
interval = "3d"
if text == "Weekly":
interval = "7d"
if text == "Monthly":
interval = "1m"
interval = text
示例3: MatplotlibWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QT import setParent [as 别名]
class MatplotlibWidget(FigureCanvas):
"""
MatplotlibWidget inherits PyQt4.QtGui.QWidget
and matplotlib.backend_bases.FigureCanvasBase
Options: option_name (default_value)
-------
parent (None): parent widget
title (''): figure title
xlabel (''): X-axis label
ylabel (''): Y-axis label
xlim (None): X-axis limits ([min, max])
ylim (None): Y-axis limits ([min, max])
xscale ('linear'): X-axis scale
yscale ('linear'): Y-axis scale
width (4): width in inches
height (3): height in inches
dpi (100): resolution in dpi
hold (False): if False, figure will be cleared each time plot is called
Widget attributes:
-----------------
figure: instance of matplotlib.figure.Figure
axes: figure axes
"""
def __init__(self, parent=None, title='Title', xlabel='x label', ylabel='y label',
width= 100, height= 100, dpi=100):
super(MatplotlibWidget, self).__init__(Figure())
self.setParent(parent)
self.figure= PlotFig.figure(figsize=(width, height), dpi=dpi)
#self.figure = Figure(figsize=(width, height), dpi=dpi)
self.canvas = FigureCanvas(self.figure)
#self.canvas.setParent(parent)
#self.canvas.setFocusPolicy(Qt.StrongFocus)
#self.canvas.setFocus()
self.grafica = self.figure.add_subplot(111)
self.grafica.set_title(title, fontsize=12)
self.grafica.set_xlabel(xlabel, fontsize=10)
self.grafica.set_ylabel(ylabel, fontsize=10)
self.grafica.grid()
self.toolbar= NavigationToolbar(self.canvas, self)
self.toolbar.setParent(parent)
vboxtab= QFormLayout()
vboxtab.addWidget(self.canvas)
vboxtab.addWidget(self.toolbar)
parent.setLayout(vboxtab)
#Canvas.setSizePolicy(self, QSizePolicy.Minimum, QSizePolicy.Minimum)
#FigureCanvas.updateGeometry(self)
# def setLayout(self, widgentparent, height, width):
# vboxtabSim= QVBoxLayout()
# vboxtabSim.addWidget(self.figure)
# vboxtabSim.addWidget(self.toolbar)
# widgentparent.setLayout(vboxtabSim)
# widgentparent.setFixedWidth(width)
# widgentparent.setFixedHeight(height)
def plot(self, x, y, title='Title', xlabel='x label', ylabel='y label', c= 'b', marker= 'o', hold= False):
if not hold:
self.grafica.clear()
self.grafica.plot(x,y)
self.grafica.set_title(title, fontsize=12)
self.grafica.set_xlabel(xlabel, fontsize=10)
self.grafica.set_ylabel(ylabel, fontsize=10)
self.grafica.grid()
self.draw()
def scatter(self, x, y, title='Title', xlabel='x label', ylabel='y label', c= 'b', marker= 'o', hold= False):
self.grafica = self.figure.add_subplot(111)
# if not hold:
# self.grafica.clear()
self.grafica.scatter(x,y, c=c, marker=marker)
self.grafica.set_title(title, fontsize=12)
self.grafica.set_xlabel(xlabel, fontsize=10)
self.grafica.set_ylabel(ylabel, fontsize=10)
self.grafica.grid()
self.draw()
def clear(self):
self.grafica.cla()
self.grafica.grid()
self.draw()