本文整理汇总了Python中matplotlib.backends.backend_qt4agg.NavigationToolbar2QT.actions方法的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QT.actions方法的具体用法?Python NavigationToolbar2QT.actions怎么用?Python NavigationToolbar2QT.actions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.NavigationToolbar2QT
的用法示例。
在下文中一共展示了NavigationToolbar2QT.actions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PlotWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QT import actions [as 别名]
class PlotWidget(QWidget):
"""A wrapper over CanvasWidget to handle additional MOOSE-specific
stuff.
modelRoot - path to the entire model our plugin is handling
dataRoot - path to the container of data tables.
pathToLine - map from moose path to Line2D objects in plot. Can
one moose table be plotted multiple times? Maybe yes (e.g., when
you want multiple other tables to be compared with the same data).
lineToDataSource - map from Line2D objects to moose paths
"""
widgetClosedSignal = pyqtSignal(object)
addGraph = pyqtSignal(object)
def __init__(self, model, graph, index, parentWidget, *args, **kwargs):
super(PlotWidget, self).__init__()
self.model = model
self.graph = graph
self.index = index
self.menu = self.getContextMenu()
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.connect( self
, SIGNAL("customContextMenuRequested(QPoint)")
, self
, SLOT("contextMenuRequested(QPoint)")
)
self.canvas = CanvasWidget(self.model, self.graph, self.index)
self.canvas.setParent(self)
self.navToolbar = NavigationToolbar(self.canvas, self)
self.hackNavigationToolbar()
self.canvas.mpl_connect('pick_event',self.togglePlot)
layout = QtGui.QGridLayout()
layout.addWidget(self.navToolbar, 0, 0)
layout.addWidget(self.canvas, 1, 0)
self.setLayout(layout)
self.pathToLine = defaultdict(set)
self.lineToDataSource = {}
self.axesRef = self.canvas.addSubplot(1, 1)
self.legend = None
desktop = QtGui.QApplication.desktop()
self.setMinimumSize(desktop.screenGeometry().width() / 4, desktop.screenGeometry().height() / 3)
self.canvas.updateSignal.connect(self.plotAllData)
self.plotAllData()
def hackNavigationToolbar(self):
# ADD Graph Action
pixmap = QPixmap(
os.path.join( config.MOOSE_ICON_DIR, 'add_graph.png' )
)
icon = QIcon(pixmap)
action = QAction(icon, "Add a graph", self.navToolbar)
# self.navToolbar.addAction(action)
action.triggered.connect( self.addGraph.emit )
self.navToolbar.insertAction(self.navToolbar.actions()[0], action)
# Delete Graph Action
pixmap = QPixmap( os.path.join( config.MOOSE_ICON_DIR,
"delete_graph.png") )
icon = QIcon(pixmap)
action = QAction(icon, "Delete this graph", self.navToolbar)
action.triggered.connect(self.delete)
self.navToolbar.insertAction(self.navToolbar.actions()[1], action)
#Toggle Grid Action
pixmap = QPixmap(
os.path.join( config.MOOSE_ICON_DIR, "grid.png" )
)
icon = QIcon(pixmap)
action = QAction(icon, "Toggle Grid", self.navToolbar)
action.triggered.connect(self.canvas.toggleGrid)
self.navToolbar.insertAction(self.navToolbar.actions()[2], action)
self.navToolbar.insertSeparator(self.navToolbar.actions()[3])
@property
def plotAll(self):
return len(self.pathToLine) == 0
def toggleLegend(self):
if self.legend is not None:
self.legend.set_visible(not self.legend.get_visible())
self.canvas.draw()
def getContextMenu(self):
menu = QMenu()
# closeAction = menu.addAction("Delete")
exportCsvAction = menu.addAction("Export to CSV")
exportCsvAction.triggered.connect(self.saveAllCsv)
toggleLegendAction = menu.addAction("Toggle legend")
toggleLegendAction.triggered.connect(self.toggleLegend)
self.removeSubmenu = menu.addMenu("Remove")
# configureAction.triggered.connect(self.configure)
# self.connect(,SIGNAL("triggered()"),
#.........这里部分代码省略.........
示例2: kmeansDialog
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QT import actions [as 别名]
class kmeansDialog(QtGui.QDialog, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
super(kmeansDialog, self).__init__(parent)
# Set up the user interface from Designer.
# After setupUI you can access any designer object by doing
# self.<objectname>, and you can use autoconnect slots - see
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
# #widgets-and-dialogs-with-auto-connect
self.setupUi(self)
# add matplotlib figure to dialog
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self.figure)
self.mpltoolbar = NavigationToolbar(self.canvas, self.widgetPlot)
lstActions = self.mpltoolbar.actions()
self.mpltoolbar.removeAction(lstActions[7])
self.layoutPlot.addWidget(self.canvas)
self.layoutPlot.addWidget(self.mpltoolbar)
# and configure matplotlib params
rcParams["font.serif"] = "Verdana, Arial, Liberation Serif"
rcParams["font.sans-serif"] = "Tahoma, Arial, Liberation Sans"
rcParams["font.cursive"] = "Courier New, Arial, Liberation Sans"
rcParams["font.fantasy"] = "Comic Sans MS, Arial, Liberation Sans"
rcParams["font.monospace"] = "Courier New, Liberation Mono"
self.values = None
self.outPath = None
self.btnOk = self.buttonBox.button(QDialogButtonBox.Ok)
self.btnClose = self.buttonBox.button(QDialogButtonBox.Close)
self.openBtn.clicked.connect(self.saveFile)
self.chkShowGrid.stateChanged.connect(self.refreshPlot)
self.chkAsPlot.stateChanged.connect(self.refreshPlot)
self.btnRefresh.clicked.connect(self.refreshPlot)
self.manageGui()
self.axes.set_title(unicode(self.tr(u"Statistic Plot")))
def manageGui(self):
self.cmbLayers.clear()
self.cmbLayers.addItems(utils.getVectorLayerNames())
self.btnRefresh.setEnabled(False)
def accept(self):
self.axes.clear()
self.spnMinX.setValue(0.0)
self.spnMaxX.setValue(0.0)
self.lstStatistics.clearContents()
self.lstStatistics.setRowCount(0)
layer = utils.getVectorLayerByName(self.cmbLayers.currentText())
statData = self.kmeansCluster(layer, self.cmbDis.currentIndex(), self.spnNum.value())
self.processFinished(statData)
self.addClassField(layer)
self.progressBar.setValue(0)
def reject(self):
QDialog.reject(self)
def setProgressRange(self, maxValue):
self.progressBar.setRange(0, maxValue)
def updateProgress(self):
self.progressBar.setValue(self.progressBar.value() + 1)
def processFinished(self, statData):
# populate table with results
self.tableData = statData[0]
self.values = statData[1]
rowCount = len(self.tableData)
self.lstStatistics.setRowCount(rowCount)
for i in xrange(rowCount):
item = QTableWidgetItem(self.tr("%d") % (i))
self.lstStatistics.setItem(i, 0, item)
tmp = self.tableData[i]
item = QTableWidgetItem(self.tr("%f") % (tmp[0]))
self.lstStatistics.setItem(i, 1, item)
item = QTableWidgetItem(self.tr("%f") % (tmp[1]))
self.lstStatistics.setItem(i, 2, item)
self.lstStatistics.resizeRowsToContents()
self.btnRefresh.setEnabled(True)
# create histogram
self.refreshPlot()
def saveFile(self):
self.outPath = QFileDialog.getSaveFileName(self, u'保存文件',u"map","jpg(*.jpg)")
self.lineEdit.setText(self.outPath)
def refreshPlot(self):
self.axes.clear()
self.axes.set_title(unicode(self.tr("Statistic Plot")))
#.........这里部分代码省略.........
示例3: MainWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QT import actions [as 别名]
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent = None):
#QtGui.QMainWindow.__init__(self, parent)#the line below is for some reason preferred
super(MainWindow, self).__init__(parent)#for some reason this is supposed to be better than line above
#QDialog.__init__( self ) #if not working with an application with mainwindow
#self.iface = iface
#self=Ui_MainWindow()#new
self.setupUi( self )#due to initialisation of Ui_MainWindow instance
self.initUI()
self.maxtstep = 0
#self.database = ''
#self.table1 = ''
#self.database_pyqt4provider = QtSql.QSqlDatabase.addDatabase("QSQLITE","db1")
def initUI(self):
self.table_ComboBox_1.clear()
self.table_ComboBox_2.clear()
self.table_ComboBox_3.clear()
for i in range (1,3):
self.clearthings(1)
self.quit_Qaction.triggered.connect(self.quit_app)
self.actionAbout.triggered.connect(self.about)
self.selectDB_QAction.triggered.connect(self.selectFile)
self.selectDB_QPushButton.clicked.connect(self.selectFile)
# whenever Time Series Table is changed, the column-combobox must be updated and TableCheck must be performed (function partial due to problems with currentindexChanged and Combobox)
#self.connect(self.table_ComboBox_1, QtCore.SIGNAL("currentIndexChanged(int)"), partial(self.Table1Changed))#currentIndexChanged caused unnecessary signals when scrolling in combobox
self.connect(self.table_ComboBox_1, QtCore.SIGNAL("activated(int)"), partial(self.Table1Changed))
self.connect(self.Filter1_ComboBox_1, QtCore.SIGNAL("activated(int)"), partial(self.Filter1_1Changed))
self.connect(self.Filter2_ComboBox_1, QtCore.SIGNAL("activated(int)"), partial(self.Filter2_1Changed))
self.connect(self.table_ComboBox_2, QtCore.SIGNAL("activated(int)"), partial(self.Table2Changed))
self.connect(self.Filter1_ComboBox_2, QtCore.SIGNAL("activated(int)"), partial(self.Filter1_2Changed))
self.connect(self.Filter2_ComboBox_2, QtCore.SIGNAL("activated(int)"), partial(self.Filter2_2Changed))
self.connect(self.table_ComboBox_3, QtCore.SIGNAL("activated(int)"), partial(self.Table3Changed))
self.connect(self.Filter1_ComboBox_3, QtCore.SIGNAL("activated(int)"), partial(self.Filter1_3Changed))
self.connect(self.Filter2_ComboBox_3, QtCore.SIGNAL("activated(int)"), partial(self.Filter2_3Changed))
self.PlotChart_QPushButton.clicked.connect(self.drawPlot)
self.Redraw_pushButton.clicked.connect( self.refreshPlot )
# Create a plot window with one single subplot
self.figure = plt.figure()
self.axes = self.figure.add_subplot( 111 )
self.canvas = FigureCanvas( self.figure )
self.mpltoolbar = NavigationToolbar( self.canvas, self.widgetPlot )
lstActions = self.mpltoolbar.actions()
self.mpltoolbar.removeAction( lstActions[ 7 ] )
self.layoutplot.addWidget( self.canvas )
self.layoutplot.addWidget( self.mpltoolbar )
# Search for saved settings and load as preset values
self.settings = QtCore.QSettings('foo','foo')
self.readsettings()
self.show()
def quit_app(self):
self.close()
#QtSql.QSqlDatabase.removeDatabase("db1")
QtCore.QCoreApplication.instance().quit()
def drawPlot(self):
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))#show the user this may take a long time...
self.storesettings() #db, table, x-col and y-col are saved as default values when user clicks 'plot chart'
self.axes.clear()
My_format = [('date_time', datetime.datetime), ('values', float)] #Define (with help from function datetime) a good format for numpy array
conn = sqlite.connect(np.unicode(self.selected_database_QLineEdit.text()),detect_types=sqlite.PARSE_DECLTYPES|sqlite.PARSE_COLNAMES)#should be cross-platform
# skapa en cursor
curs = conn.cursor()
i = 0
nop=0# nop=number of plots
self.p=[]
self.plabels=[]
if not (self.table1 == '' or self.table1==' ') and not (self.xcol1== '' or self.xcol1==' ') and not (self.ycol1== '' or self.ycol1==' '): #if anything is to be plotted from tab 1
self.maxtstep = self.spnmaxtstep.value() # if user selected a time step bigger than zero than thre may be discontinuous plots
plottable1='y'
filter1 = np.unicode(self.Filter1_ComboBox_1.currentText())
filter1list = self.Filter1_QListWidget_1.selectedItems()
filter2 = np.unicode(self.Filter2_ComboBox_1.currentText())
filter2list= self.Filter2_QListWidget_1.selectedItems()
nop += max(len(filter1list),1)*max(len(filter2list),1)
#self.p= [None]*nop#list for plot objects
self.p.extend([None]*nop)#list for plot objects
self.plabels.extend([None]*nop)# List for plot labels
while i < len(self.p):
if not (filter1 == '' or filter1==' ') and not (filter2== '' or filter2==' '):
for item1 in filter1list:
for item2 in filter2list:
sql = r""" select """ + np.unicode(self.xcol_ComboBox_1.currentText()) + """, """ + np.unicode(self.ycol_ComboBox_1.currentText()) + """ from """ + np.unicode(self.table_ComboBox_1.currentText()) + """ where """ + filter1 + """='""" + np.unicode(item1.text())+ """' and """ + filter2 + """='""" + np.unicode(item2.text())+ """' order by """ + np.unicode(self.xcol_ComboBox_1.currentText())
self.plabels[i] = np.unicode(item1.text()) + """, """ + np.unicode(item2.text())
self.createsingleplotobject(sql,i,My_format,curs,self.PlotType_comboBox_1.currentText())
i += 1
elif not (filter1 == '' or filter1==' '):
for item1 in filter1list:
sql = r""" select """ + np.unicode(self.xcol_ComboBox_1.currentText()) + """, """ + np.unicode(self.ycol_ComboBox_1.currentText()) + """ from """ + np.unicode(self.table_ComboBox_1.currentText()) + """ where """ + filter1 + """='""" + np.unicode(item1.text())+ """' order by """ + np.unicode(self.xcol_ComboBox_1.currentText())
self.plabels[i] = np.unicode(item1.text())
self.createsingleplotobject(sql,i,My_format,curs,self.PlotType_comboBox_1.currentText())
#.........这里部分代码省略.........