本文整理汇总了Python中matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg.show方法的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QTAgg.show方法的具体用法?Python NavigationToolbar2QTAgg.show怎么用?Python NavigationToolbar2QTAgg.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg
的用法示例。
在下文中一共展示了NavigationToolbar2QTAgg.show方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
class MatplotlibPlot:
""" Class encapsulating a matplotlib plot"""
def __init__(self, parent = None, dpi = 100, size = (5,5)):
""" Class initialiser """
self.dpi = dpi
self.figure = Figure(size, dpi = self.dpi)
self.canvas = FigureCanvas(self.figure)
self.canvas.setParent(parent)
# Create the navigation toolbar, tied to the canvas
self.toolbar = NavigationToolbar(self.canvas, parent)
self.canvas.show()
self.toolbar.show()
# Reset the plot landscape
self.figure.clear()
def plotMultiPixel(self, info, data):
""" Generate multi-pixel plot """
# Tabula Rasa
self.figure.clear()
rows = math.ceil(math.sqrt(info['nbeams']))
# Display a subplot per beam (randomly for now)
for i in range(info['nbeams']):
ax = self.figure.add_subplot(rows, rows, i)
ax.plot(data[:,512,i])
def updatePlot(self):
self.canvas.draw()
示例2: __init__
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
class MatplotlibPlot:
""" Class encapsulating an matplotlib plot"""
def __init__(self, parent = None, dpi = 100, size = (5,4)):
""" Class initialiser """
self.dpi = dpi
self.figure = Figure(size, dpi = self.dpi)
self.canvas = FigureCanvas(self.figure)
self.canvas.setParent(parent)
# Create the navigation toolbar, tied to the canvas
self.toolbar = NavigationToolbar(self.canvas, parent)
self.canvas.show()
self.toolbar.show()
def plotCurve(self, data, xAxisRange = None, yAxisRange = None, xLabel = "", yLabel = ""):
""" Plot the data as a curve"""
# clear the axes and redraw the plot anew
self.figure.clear()
self.axes = self.figure.add_subplot(111)
self.axes.grid(True)
self.axes.plot(range(np.size(data)), data)
if xAxisRange is not None:
self.xAxisRange = xAxisRange
self.axes.xaxis.set_major_formatter(ticker.FuncFormatter(
lambda x, pos=None: '%.2f' % self.xAxisRange[x] if 0 <= x < len(xAxisRange) else ''))
for tick in self.axes.xaxis.get_ticklabels():
tick.set_rotation(15)
if yAxisRange is not None:
self.yAxisRange = yAxisRange
self.axes.xaxis.set_major_formatter(ticker.FuncFormatter(
lambda x, pos=None: '%.1f' % self.yAxisRange[y] if 0 <= y < len(yAxisRange) else ''))
for tick in self.axes.yaxis.get_ticklabels():
tick.set_rotation(15)
self.axes.xaxis.set_label_text(xLabel)
self.axes.yaxis.set_label_text(yLabel)
self.canvas.draw()
示例3: LMatplotlibWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
class LMatplotlibWidget(LWidget):
def __init__(self, parent=None):
super(LMatplotlibWidget, self).__init__(parent)
self.setName(WIDGET_NAME)
self.buildUi()
self.dataContainer = LMyDataContainer(self)
self.actions = LMyActions(self.dataContainer,self)
self.setDebugLevel(5)
self.updateUi()
@LInAndOut(DEBUG & WIDGETS)
def buildUi(self):
self.verticalLayout = QVBoxLayout(self)
self.figure = Figure()
self.canvas = Canvas(self.figure) # <-- figure required
self.navigationToolbar = NavigationToolbar(self.canvas, self)
self.verticalLayout.addWidget(self.canvas)
self.verticalLayout.addWidget(self.navigationToolbar)
#Canvas.setSizePolicy(self.canvas, QSizePolicy.Expanding, QSizePolicy.Expanding)
#Canvas.updateGeometry(self.canvas)
@LInAndOut(DEBUG & WIDGETS)
def updateUi(self):
left = self.dataContainer.leftMargin
bottom = self.dataContainer.bottomMargin
right = self.dataContainer.rightMargin
top = self.dataContainer.topMargin
wspace = self.dataContainer.verticalSeparation
hspace = self.dataContainer.horizontalSeparation
self.figure.subplots_adjust(left, bottom, right, top, wspace, hspace)
if self.dataContainer.showNavigationToolbar:
self.navigationToolbar.show()
else:
self.navigationToolbar.hide()
#----------------------------------------------------------------------
# Interface (set)
@LInAndOut(DEBUG & WIDGETS)
def setOptions(self, options):
super(LMatplotlibWidget, self).setOptions(options)
if options.verboseLevel is not None:
self.setVerboseLevel(options.verboseLevel)
if options.navigationToolbar is not None:
self.showNavigationToolbar(options.navigationToolbar)
self.updateUi()
@LInAndOut(DEBUG & WIDGETS)
def setVerboseLevel(self, level):
self.dataContainer.verboseLevel = level
#----------------------------------------------------------------------
# Interface (get)
def getFigure(self):
return self.figure
#----------------------------------------------------------------------
# Interface (misc)
@LInAndOut(DEBUG & WIDGETS)
def showNavigationToolbar(self, flag=True):
self.dataContainer.showNavigationToolbar = flag
self.updateUi()
@LInAndOut(DEBUG & WIDGETS)
def snapshot(self, fileName = None):
if fileName is None:
caption = "%s - Save File" % self.name
filter = "PNG Image (*.png);;All files (*.*)"
fileName = QFileDialog.getSaveFileName(self.parent(), caption=caption,filter=filter )
fileName = "%s" % fileName
if len(fileName) > 0:
self.figure.savefig(fileName, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format=None, transparent=False, bbox_inches=None, pad_inches=0.1)
@LInAndOut(DEBUG & WIDGETS)
def draw(self):
self.canvas.draw()
示例4: plothistogram
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
class plothistogram(QFrame):
def __init__(self, parent):
print "__init__()" # DEBUG
QFrame.__init__(self)
self.parent=parent
#self.setModal(False)
self.data1=self.parent.y1 # get plotted y values from solutions plot
self.data2=self.parent.y2 # get plotted y values from parameter plot
self.nbins=50 # default=50 bins
self.parameter=self.parent.parent.parametersComboBox.currentText()
self.data=self.parent.y2 # set histogram to solver parameter data
#print "self.data = ", self.data # DEBUG
# Create canvas for plotting
self.rim=0.1
self.fig = Figure((5, 4), dpi=100)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self)
self.fig.subplots_adjust(left=self.rim, right=1.0-self.rim, top=1.0-self.rim, bottom=self.rim) # set a small rim
self.mpl_toolbar = NavigationToolbar(self.canvas, self)
self.mpl_toolbar.show() # first hide the toolbar
self.ax=self.fig.add_subplot(111)
self.createWidgets()
self.createLayout()
self.connectSignals()
self.setLabels()
self.plot()
def createWidgets(self):
#print "createWidgets()" # DEBUG
self.closeButton=QPushButton("Close")
self.closeButton.setToolTip("close this plotwindow")
self.closeButton.show()
self.histogramBinSpin=QSpinBox() # spinbox for histogram binsize
self.histogramBinSpin.setToolTip("Number of bins to histogram into")
self.histogramBinSpin.setMinimum(5)
#self.histogramBinSpin.setMaximum(150) # set a maximum of 150 (reasonable?)
self.histogramBinSpin.setSingleStep(10) # allow only stepping by 10
self.histogramBinSpin.setMaximumWidth(120)
self.histogramBinSpin.setMinimumHeight(25)
self.histogramBinSpin.setValue(self.nbins)
self.histogramBinSpin.show()
self.histogramBinLabel=QLabel("Bins")
self.normedCheckBox=QCheckBox()
self.normedCheckLabel=QLabel("Normalize")
self.normedCheckBox.setToolTip("Normalize histogram")
self.normedCheckBox.show()
#self.dpi = 100
self.dataComboBox=QComboBox()
self.dataComboBox.addItem(self.parent.parent.parmValueComboBox.currentText())
self.dataComboBox.addItem(self.parent.parent.parametersComboBox.currentText())
self.dataComboBox.setMaximumWidth(120)
self.dataComboBox.setMinimumHeight(25)
self.dataComboBox.setCurrentIndex(1)
def createLayout(self):
#print "createLayout()" # DEBUG
self.normedLayout=QHBoxLayout()
self.normedLayout.addWidget(self.normedCheckBox)
self.normedLayout.addWidget(self.normedCheckLabel)
self.buttonLayout=QVBoxLayout()
self.plotLayout=QVBoxLayout()
self.mainLayout=QHBoxLayout()
self.buttonLayout.addLayout(self.normedLayout)
#self.buttonLayout.addWidget(self.normedCheckBox)
#self.buttonLayout.addWidget(self.normedCheckLabel)
self.buttonLayout.addWidget(self.histogramBinSpin)
self.buttonLayout.addWidget(self.dataComboBox)
self.buttonLayout.insertStretch(-1)
self.buttonLayout.addWidget(self.closeButton)
self.plotLayout.addWidget(self.canvas)
self.plotLayout.addWidget(self.mpl_toolbar)
self.mainLayout.addLayout(self.buttonLayout)
self.mainLayout.addLayout(self.plotLayout)
self.setLayout(self.mainLayout)
def setLabels(self):
self.ax.xlabel="Bin"
self.ax.ylabel="N"
def setTitle(self):
#=self.parent.parametersComboBox.currentText()
#self.ax.xlabel=self.parmValueComboBox.currentText()
#self.ax.xlabel="Bin No."
#self.ax.ylabel="n"
self.ax.title=self.parent.parent.parametersComboBox.currentText()
def connectSignals(self):
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
class MatplotlibPlot:
""" Class encapsulating a matplotlib plot"""
def __init__(self, parent = None, dpi = 100, size = (5,5)):
""" Class initialiser """
self.dpi = dpi
self.figure = Figure(size, dpi = self.dpi)
self.canvas = FigureCanvas(self.figure)
self.canvas.setParent(parent)
# Create the navigation toolbar, tied to the canvas
self.toolbar = NavigationToolbar(self.canvas, parent)
self.canvas.show()
self.toolbar.show()
# Reset the plot landscape
self.figure.clear()
self.nSubplot=0
def resetSubplots(self):
self.nSubplot=0
def plotCurve(self, data, xAxisRange = None, yAxisRange = None, xLabel = "", yLabel = "", title="", label="", plotLog=False, nSubplots=1, hold=False):
""" Plot the data as a curve"""
if len(data) != 0:
# Plan what dimensions the grid will have if there are to be subplots
# Attempt to be roughly square but give preference to vertical stacking
nSubplots_v = np.ceil(np.sqrt(nSubplots))
nSubplots_h = np.ceil(float(nSubplots)/nSubplots_v)
yAxisRange=np.array(yAxisRange)
if yAxisRange is not None:
auto_scale_y = False
if plotLog:
data[data==0] = 1
yAxisRange[yAxisRange==0] = 1
data= 10*np.log(data)
yAxisRange = 10*np.log(yAxisRange)
else:
auto_scale_y = True
# draw the new plot
if self.nSubplot < nSubplots:
self.axes = self.figure.add_subplot(nSubplots_v, nSubplots_h, self.nSubplot+1, label=label, title=title, ylim=yAxisRange) #subplots start from 1
self.axes.grid(True)
#if plotLog:
# self.axes.semilogy(range(np.size(data)), data, scaley=auto_scale_y)
#else:
# self.axes.plot(range(np.size(data)), data, scaley=auto_scale_y)
self.axes.plot(range(np.size(data)), data, scaley=auto_scale_y)
#if xAxisRange is not None:
# self.xAxisRange = xAxisRange
# self.axes.xaxis.set_major_formatter(ticker.FuncFormatter(
# lambda x, pos=None: '%.2f' % self.xAxisRange[x] if 0 <= x < len(xAxisRange) else ''))
# for tick in self.axes.xaxis.get_ticklabels():
# tick.set_rotation(15)
#if yAxisRange is not None:
# self.yAxisRange = yAxisRange
# self.axes.xaxis.set_major_formatter(ticker.FuncFormatter(
# lambda x, pos=None: '%.1f' % self.yAxisRange[y] if 0 <= y < len(yAxisRange) else ''))
# for tick in self.axes.yaxis.get_ticklabels():
# tick.set_rotation(15)
self.axes.xaxis.set_label_text(xLabel)
self.axes.yaxis.set_label_text(yLabel)
# Increment the subplot number ready for the plot method to be called again.
# Count modulo number of subplots so that nSubplots=1 is the same as having a
# single shared axis.
# Skip this step if hold is set, in which case the next plot will be overlaid with the current one
if not hold:
self.nSubplot = (self.nSubplot + 1)
def plotNewCurve(self, data, xAxisRange=None, yAxisRange=None, xLabel="", yLabel="", plotLog=False):
# Clear the plot
self.figure.clear()
# Start from a new set of subplots
self.nSubplot = 0
self.plotCurve(self, data, xAxisRange=xAxisRange, yAxisRange=yAxisRange, xLabel=xLabel, yLabel=yLabel, plotLog=plotLog)
def updatePlot(self):
self.canvas.draw()
示例6: __init__
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
class MatplotlibPlot:
""" Class encapsulating an matplotlib plot """
def __init__(self, parent = None, dpi = 100, size = (5,4)):
""" Class initialiser """
self.dpi = dpi
self.figure = Figure(dpi = self.dpi)
self.canvas = FigureCanvas(self.figure)
self.canvas.setParent(parent)
# Create the navigation toolbar, tied to the canvas
self.toolbar = NavigationToolbar(self.canvas, parent)
self.canvas.show()
self.toolbar.show()
def plotCurve(self, data, numCurves = 1, labels = None, xAxisRange = None, yAxisRange = None, xLabel = "", yLabel = ""):
""" Normal plots """
self.figure.clear()
self.axes = self.figure.add_subplot(111)
self.axes.grid(True)
# Set empty labels if non defined
if labels is None:
labels = ['' for i in range(numImages)]
# Place all plots in axes
for i in range(numCurves):
self.axes.plot(data[:,i], label=labels[i])
self.axes.set_xlim((0, len(data[:,i])))
# Final touches
self.axes.xaxis.set_label_text(xLabel)
self.axes.yaxis.set_label_text(yLabel)
self.canvas.draw()
def subplotCurve(self, data, numPlots = 1, labels = None, xAxisRange = None, yAxisRange = None, xLabel = "", yLabel = ""):
""" Subplot mode """
self.figure.clear()
# Set empty labels if non defined
if labels is None:
labels = ['' for i in range(numImages)]
if numPlots == 1:
ax = self.figure.add_subplot(111)
ax.plot(data[:])
ax.set_xlabel(xLabel)
ax.set_ylabel(yLabel)
ax.set_title(labels[0])
ax.grid(True)
else:
# Plot each image
num_rows = ceil(sqrt(numPlots))
for i in range(numPlots):
ax = self.figure.add_subplot(num_rows, num_rows, i + 1)
ax.plot(data[:,i])
ax.set_xlim((0, len(data[:,i])))
ax.set_xlabel(xLabel)
ax.set_ylabel(yLabel)
ax.set_title(labels[i])
ax.grid(True)
# Final touches
self.figure.tight_layout()
self.canvas.draw()
def plotImage(self, data, numImages = 1, labels = None, xAxisRange = None, yAxisRange = None, xLabel = "", yLabel = ""):
""" Image plot """
self.figure.clear()
self.axes = self.figure.add_subplot(111)
# Show image
im = self.axes.imshow(data, origin='lower', aspect='auto')
# Final touches
self.axes.xaxis.set_label_text(xLabel)
self.axes.yaxis.set_label_text(yLabel)
self.figure.colorbar(im)
self.canvas.draw()
def subplotImage(self, data, numImages = 1, labels = None, xAxisRange = None, yAxisRange = None, xLabel = "", yLabel = ""):
""" Image subplot """
# Clear figure
self.figure.clear()
# Set empty labels if non defined
if labels is None:
labels = ['' for i in range(numImages)]
# Plot each image
num_rows = ceil(sqrt(numImages))
for i in range(numImages):
ax = self.figure.add_subplot(num_rows, num_rows, i + 1)
im = ax.imshow(data[:,:,i], origin='lower', aspect='auto')
#.........这里部分代码省略.........
示例7: PlotWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
class PlotWindow(QFrame):
# Init the class: create plot window and canvas layout (and corresponding buttons)
# Steps contains a dictionary of dictionaries with the identified steps
#
def __init__(self, parent):
#QFrame.__init__(self)
QMainWindow.__init__(self, None)
self.setWindowTitle('BBS timing statistics')
self.parent=parent # Parent: BBSTiming class
self.currentPlotStyle="bar" # current style of plot: bar, colorbar, lines
self.plotStyles=["bar", "colorbar", "line"] # supported plot styles #
self.summation=False # show "individual" execution times or "summation"
self.fig=None # figure
self.axes=None # plot axes
self.create_main_frame()
self.createWidgets()
self.createLayouts()
self.createConnections()
self.setMinimumWidth(700)
self.setMinimumHeight(400)
# Create a main frame
#
def create_main_frame(self):
self.main_frame = QWidget()
self.dpi = 75
self.setMinimumWidth(300)
self.setMinimumHeight(300)
# We want matplotlib export functionality, so include toolbar
# MPL Canvas and Toolbar
# Create canvas for plotting
self.fig = Figure((5, 4), dpi=75)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self)
self.fig.subplots_adjust(left=0.1, right=0.96, top=0.94, bottom=0.06) # set a small rim
self.mpl_toolbar = NavigationToolbar(self.canvas, self)
self.mpl_toolbar.show() # first hide the toolbar
# Create the layouts for the widgets
#
def createLayouts(self):
# Layouts
self.buttonLayout=QVBoxLayout()
self.canvasLayout=QVBoxLayout()
self.mainLayout=QHBoxLayout()
# Add Widgets to the layout
self.buttonLayout.addWidget(self.loadButton)
self.buttonLayout.addWidget(self.quitButton)
self.buttonLayout.insertStretch(-1)
self.subStepsLayout=QHBoxLayout()
self.subStepsLayout.addWidget(self.showSubstepsCheckBox)
self.subStepsLayout.addWidget(self.showSubstepsLabel)
self.buttonLayout.addLayout(self.subStepsLayout)
self.showIndividualStepsLayout=QHBoxLayout()
self.showIndividualStepsLayout.addWidget(self.showIndividualCheckBox)
self.showIndividualStepsLayout.addWidget(self.showIndividualLabel)
self.buttonLayout.addLayout(self.showIndividualStepsLayout)
self.buttonLayout.addWidget(self.stepComboBox)
#self.buttonLayout.addWidget(self.stepListView)
self.buttonLayout.addWidget(self.substepComboBox)
self.buttonLayout.addWidget(self.keywordComboBox)
self.buttonLayout.addWidget(self.plotStyleComboBox)
self.buttonLayout.addWidget(self.stepComboBox)
self.buttonLayout.addWidget(self.plotButton)
self.buttonLayout.insertStretch(-1)
self.canvasLayout.addWidget(self.canvas)
self.canvasLayout.addWidget(self.mpl_toolbar)
self.mainLayout.addLayout(self.buttonLayout)
self.mainLayout.addLayout(self.canvasLayout)
self.setLayout(self.mainLayout)
# Create GUI widgets
#
def createWidgets(self):
#print "createWidgets()" # DEBUG
self.loadButton=QPushButton("Load logfile")
self.loadButton.setToolTip('load a BBS kernellog file')
self.loadButton.setMaximumWidth(200)
self.quitButton=QPushButton("Quit")
self.quitButton.setMaximumWidth(200)
self.quitButton.setToolTip('Quit the application')
self.quitButton.setMaximumWidth(200)
#.........这里部分代码省略.........
示例8: rebuild_widget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
def rebuild_widget(self, number_of_plots, plot_stretching):
self.__number_of_plots = number_of_plots
self.__plot_stretching = plot_stretching
ids = []
if self.__top_vbox.count() < self.__number_of_plots:
ids = range(self.__top_vbox.count(), self.__number_of_plots)
for i in ids:
label = QLabel()
label.setFont(self.__font)
label.setAlignment(Qt.AlignCenter)
# Create the mpl Figure and FigCanvas objects.
# 5x4 inches, 100 dots-per-inch
#
#dpi = 100
#self.fig = Figure((5.0, 4.0), dpi=self.dpi)
fig = pyplot.figure()
canvas = FigureCanvas(fig)
canvas.setParent(self)
# Since we have only one plot, we can use add_axes
# instead of add_subplot, but then the subplot
# configuration tool in the navigation toolbar wouldn't
# work.
#
axes = fig.add_subplot(111)
# Create the navigation toolbar, tied to the canvas
#
mpl_toolbar = NavigationToolbar(canvas, self, False)
if self.__show_toolbar:
mpl_toolbar.show()
else:
mpl_toolbar.hide()
# Other GUI controls
#
tmp_vbox = QVBoxLayout()
tmp_vbox.addWidget(label)
tmp_vbox.addWidget(canvas, 1)
tmp_vbox.addWidget(mpl_toolbar)
widget = QWidget()
widget.setLayout(tmp_vbox)
self.__plots.append((label, canvas, fig, axes, mpl_toolbar, widget))
self.__plot_infos.append((self.PLOT_TYPE_NONE, '', None, {}))
self.__top_vbox.addWidget(widget)
for i in xrange(self.__number_of_plots):
stretch = 0
if plot_stretching != None:
stretch = plot_stretching[i]
self.__top_vbox.setStretch(i, stretch)
else:
self.__top_vbox.setStretch(i, 1)
plot = self.__plots[i]
label, canvas, fig, axes, mpl_toolbar, widget = plot
widget.show()
for i in xrange(self.__number_of_plots, self.__top_vbox.count()):
plot = self.__plots[i]
label, canvas, fig, axes, mpl_toolbar, widget = plot
widget.hide()
if self.__show_menu:
menubar = QMenuBar()
save_menu = menubar.addMenu("&Save")
menu_items = []
for i,plot_info in enumerate(self.__plot_infos):
plot_caption = plot_info[1]
menu_name = "Save &plot '%s' [%d]" % (plot_caption, i+1)
if len(plot_caption) == 0:
menu_name = "Save &plot #%d" % (i+1)
save_plot_action = self.__make_action(menu_name,
shortcut="Ctrl+P",
slot=functools.partial(self.on_save_plot, i))
menu_items.append(save_plot_action)
menu_items.append(None)
save_all_action = self.__make_action("Save &all plots",
shortcut="Ctrl+A", slot=self.on_save_all_plots)
menu_items.append(save_all_action)
self.__add_actions(save_menu, menu_items)
self.layout().setMenuBar(menubar)
示例9: plotCorrmatrix
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
class plotCorrmatrix(QDialog):
def __init__(self, parent, corrmatrix):
QFrame.__init__(self)
self.setWindowTitle("Correlation Matrix")
self.corrmatrix=[[]]
self.rank=None
self.rim=0.05
self.parent=parent # parent object/class
self.fig=None
# Create canvas for plotting
self.fig = Figure((7, 7), dpi=100)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self)
self.fig.subplots_adjust(left=self.rim, right=1.0-self.rim, top=1.0-self.rim, bottom=self.rim) # set a small rim
self.ax=self.fig.add_subplot(111)
self.mpl_toolbar = NavigationToolbar(self.canvas, self)
self.mpl_toolbar.show()
self.setMinimumWidth(700)
self.setMinimumHeight(700)
self.corrmatrix=corrmatrix
self.xLabel="Parameter index"
self.yLabel="Parameter index"
self.createWidgets()
self.createLayouts()
self.connectSignals()
self.plot(self.corrmatrix)
def createWidgets(self):
# Get time indices (and frequency range) from solverdialog class according to plotwindow index
self.index = np.searchsorted(self.parent.x, [self.parent.xdata])[0]
print "self.index = ", self.index # DEBUG
self.start_time=self.parent.parent.solverQuery.timeSlots[self.index]['STARTTIME']
self.end_time=self.parent.parent.solverQuery.timeSlots[self.index]['ENDTIME']
self.start_freq=self.parent.parent.solverQuery.frequencies[self.parent.parent.frequencyStartSlider.value()]['STARTFREQ']
self.end_freq=self.parent.parent.solverQuery.frequencies[self.parent.parent.frequencyEndSlider.value()]['ENDFREQ']
self.timeLabel=QLabel("Time cell")
self.startTimeLabel=QLabel("S: " + str(self.parent.parent.convertDate(self.start_time)))
self.endTimeLabel=QLabel("E: " + str(self.parent.parent.convertDate(self.end_time)))
self.startTimeLabel.show()
self.endTimeLabel.show()
self.freqLabel=QLabel("Freq cell")
self.startFreqLabel=QLabel("S: " + str(self.start_freq) + " Hz")
self.endFreqLabel=QLabel("E: " + str(self.end_freq) + " Hz")
self.startFreqLabel.show()
self.endFreqLabel.show()
self.closeButton=QPushButton()
self.closeButton=QPushButton()
self.closeButton.setText('Close')
self.closeButton.setToolTip('close this plotcorrmatrix window')
self.closeButton.setMaximumWidth(120)
self.closeButton.show()
self.prevButton=QPushButton("Prev")
self.nextButton=QPushButton("Next")
def createLayouts(self):
self.buttonLayout=QVBoxLayout() # layout containing widgets
self.matrixLayout=QVBoxLayout() # layout containing canvas and toolbar
self.mainLayout=QHBoxLayout()
self.buttonLayout.addWidget(self.timeLabel)
self.buttonLayout.addWidget(self.startTimeLabel)
self.buttonLayout.addWidget(self.endTimeLabel)
self.buttonLayout.addWidget(self.freqLabel)
self.buttonLayout.addWidget(self.startFreqLabel)
self.buttonLayout.addWidget(self.endFreqLabel)
self.prevNextLayout=QHBoxLayout()
if self.parent.parent.xAxisType!="Iteration": # we don't support previous and next in iteration mode
self.prevNextLayout.addWidget(self.prevButton)
self.prevNextLayout.addWidget(self.nextButton)
self.buttonLayout.addLayout(self.prevNextLayout)
self.buttonLayout.insertStretch(-1)
self.buttonLayout.addWidget(self.closeButton)
self.matrixLayout.addWidget(self.canvas)
self.matrixLayout.addWidget(self.mpl_toolbar)
self.mainLayout.addLayout(self.buttonLayout)
self.mainLayout.addLayout(self.matrixLayout)
self.setLayout(self.mainLayout)
def connectSignals(self):
self.connect(self.closeButton, SIGNAL('clicked()'), SLOT('close()'))
#.........这里部分代码省略.........
示例10: MatplotlibWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
#.........这里部分代码省略.........
selected_values_mean = nanmean(selected_values)
selected_value_max = np.nanmax(selected_values)
selected_value_min = np.nanmin(selected_values)
return selected_dates, selected_values, selected_values_mean, selected_value_max, selected_value_min
def on_select_axes(self, xmin, xmax):
""" A select handler for SpanSelector that updates axes with the new x and y limits selected by user """
selected_dates, selected_values, selected_values_mean, selected_value_max, selected_value_min = self.on_select_helper(xmin, xmax)
# plot the selected values and update plots limits and text
self.axes.plot(selected_dates, selected_values, self.color_str)
self.axes.set_xlim(selected_dates[0], selected_dates[-1])
self.axes.set_ylim(selected_values.min(), selected_values.max())
text = 'mean = %.2f\nmax = %.2f\nmin = %.2f' % (selected_values_mean, selected_value_max, selected_value_min)
self.axes_text.set_text(text)
# draw the updated plot
self.canvas.draw()
def toggle_selector(self, radio_button_label):
"""
A toggle radio buttons for the matplotlib SpanSelector widget.
"""
if radio_button_label == "Span On":
self.span_selector.visible = True
self.matplotlib_toolbar.hide()
elif radio_button_label == "Span Off":
self.span_selector.visible = False
self.matplotlib_toolbar.show()
self.plot_watertxt_parameter(watertxt_data = self.watertxt_data, name = self.parameter["name"])
def clear_watertxt_plot(self):
""" Clear the plot axes """
self.figure.clear()
self.canvas.draw()
def reset_watertxt_plot(self):
""" Clear the plot axes """
self.axes.clear()
self.canvas.draw()
self.axes.grid(True)
#-------------------------------- WATER.txt Parameter Comparison Plot ------------------------------------
def setup_watertxtcmp_plot(self):
""" Setup the watertxt plot """
self.clear_watertxtcmp_plot()
# set up axes and its properties
self.axes1 = self.figure.add_subplot(211)
self.axes2 = self.figure.add_subplot(212, sharex = self.axes1)
self.axes1.grid(True)
self.axes2.grid(True)
def plot_watertxtcmp_parameter(self, watertxt_data1, watertxt_data2, filename1, filename2, name):
""" Plot a parameter from a WATER.txt file """
示例11: PlotWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import show [as 别名]
class PlotWindow(QFrame):
# Init the class: create plot window and canvas layout (and corresponding buttons)
#
def __init__(self, parent):
QDialog.__init__(self)
self.rim=0.05 # rim around plot
# The plot class holds its data now, so that it can be exported after a different
# PlotWindow has been created
self.parent=parent # parent object/class
self.fig=None
self.showCursor=False
self.cursorId=None
self.markerId=None
self.marker1=None # position marker in the plot
self.marker2=None
self.x = parent.x # plotted x axis data
self.x0 = self.parent.solverQuery.getTimeSlots()[0]['STARTTIME']
self.y1 = parent.y1 # plotted y axis data
self.y2 = parent.y2 # plotted y2 axis data
self.xdata = None # cursor click x coordinate in data value
self.ydata = None # cursor click y coordinate in data value
self.messages = parent.messages # solver messages
# Create canvas for plotting
self.fig = Figure((5, 4), dpi=100)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self)
self.fig.subplots_adjust(left=self.rim+0.05, right=1.0-self.rim, top=1.0-self.rim, bottom=self.rim) # set a small rim
self.mpl_toolbar = NavigationToolbar(self.canvas, self)
self.mpl_toolbar.show() # first hide the toolbar
self.setMinimumWidth(900)
self.setMinimumHeight(600)
self.setWindowTitle = self.parent.tableName + ": " + str(self.parent.solverQuery.getRank()) + " Parameters"
self.createWidgets()
self.createConnections()
self.createLayouts()
def createWidgets(self):
# Create Buttons for data export
#
self.exportButton=QPushButton("&Export Data")
self.exportButton.setToolTip("Export the currently plotted data")
self.exportButton.setMaximumWidth(100)
self.exportComboBox=QComboBox()
self.exportComboBox.addItem("ASCII")
# export in Matlab format is only possible if scipy.io module has been imported
if self.parent.haveModule('scipy') == True or self.parent.haveModule('scipy.io') == True:
self.exportComboBox.addItem("Matlab")
self.exportComboBox.setToolTip('File format for exporting data')
self.exportComboBox.setMaximumWidth(100)
self.exportComboBox.setMinimumHeight(25)
self.showCursorCheckBox=QCheckBox("Show cursor")
self.showCursorCheckBox.setToolTip("Show a marker line in plot")
self.showCursorCheckBox.setCheckState(Qt.Unchecked) # default off
self.histogramButton=QPushButton("&Histogram") # button to create a histogram
self.histogramButton.setToolTip("Create a histogram of the current parameter")
self.histogramButton.setMaximumWidth(150)
self.histogramButton.setToolTip('Create a histogram of current data')
self.onClickLabel=QLabel("On click display:")
self.onClickComboBox=QComboBox()
self.onClickComboBox.setMaximumWidth(150)
self.onClickComboBox.setToolTip('What to display when data point in graph is clicked')
self.onClickComboBox.addItem("CorrMatrix") # first, default = correlation matrix
self.onClickComboBox.addItem("Zoom")
#self.onClickComboBox.addItem("Per iteration")
#self.onClickComboBox.addItem("CorrMatrix and Iterations")
self.solverMessageLabel=QLabel("Solver Message:")
self.solverMessageText=QLineEdit()
self.solverMessageText.setText('Undefined')
self.solverMessageText.setToolTip('Message returned by LSQFit after iteration')
self.solverMessageText.setReadOnly(True)
self.solverMessageText.setMaximumWidth(125)
self.closeButton=QPushButton()
self.closeButton.setText('Close')
self.closeButton.setToolTip('close this plot window')
self.closeButton.setMaximumWidth(120)
def createConnections(self):
# Set connections
self.connect(self.exportButton, SIGNAL('clicked()'), self.on_export)
self.connect(self.histogramButton, SIGNAL('clicked()'), self.on_histogram)
self.connect(self.closeButton, SIGNAL('clicked()'), SLOT('close()'))
self.connect(self.showCursorCheckBox, SIGNAL('stateChanged(int)'), self.on_cursor)
self.connect(self.onClickComboBox, SIGNAL('valueChanged(int)'), self.on_onClickComboBox)
#.........这里部分代码省略.........