本文整理汇总了Python中PyQt4.Qwt5.QwtPlot.canvas方法的典型用法代码示例。如果您正苦于以下问题:Python QwtPlot.canvas方法的具体用法?Python QwtPlot.canvas怎么用?Python QwtPlot.canvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qwt5.QwtPlot
的用法示例。
在下文中一共展示了QwtPlot.canvas方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: qwtchart
# 需要导入模块: from PyQt4.Qwt5 import QwtPlot [as 别名]
# 或者: from PyQt4.Qwt5.QwtPlot import canvas [as 别名]
class qwtchart(chart):
colours = {'red' : Qt.red,
'green' : Qt.green,
'blue' : Qt.blue,
'yellow' : Qt.yellow,
'magenta': Qt.magenta,
'black' : Qt.black}
styles = {'-' : Qt.SolidLine,
'--': Qt.DashLine,
':' : Qt.DotLine,
'-.': Qt.DashDotLine}
def getPen(self, colour, style):
return QPen(self.colours[colour], 1, self.styles[style])
def __init__(self, spurset, fef, parent):
chart.__init__(self, spurset, fef, parent)
self.plot = QwtPlot(parent)
self.plot.setAxisScale(xaxis, self.spurset.RFmin,
self.spurset.RFmax)
self.plot.setAxisScale(yaxis, -self.spurset.dspan/2,
self.spurset.dspan/2)
self.plot.setCanvasBackground(Qt.white)
grid = QwtPlotGrid()
grid.setMajPen(QPen(Qt.black, 1, Qt.DotLine))
grid.attach(self.plot)
self.plot.insertLegend(QwtLegend(self.parent), QwtPlot.ExternalLegend)
# a picker to be used for the front-end filter parallelogram
self.picker = QwtPlotPicker(xaxis, yaxis,
QwtPicker.PointSelection,
QwtPlotPicker.NoRubberBand,
QwtPicker.AlwaysOff,
self.plot.canvas())
# gonna need this to implement ondrop()
self._mouseRelease = self.picker.widgetMouseReleaseEvent
self._picked_obj = None
self.picker.connect(self.picker, SIGNAL('appended(const QPoint&)'),
self.onpick)
self.picker.connect(self.picker, SIGNAL('moved(const QPoint&)'),
self.ondrag)
# all about the monkey-patching
self.picker.widgetMouseReleaseEvent = self.ondrop
def redraw(self):
xscale = self.plot.axisScaleDiv(xaxis)
yscale = self.plot.axisScaleDiv(yaxis)
#TODO check if it hurts to just set the scales every time, as in mpl
if (xscale.lowerBound() != self.spurset.RFmin or
xscale.upperBound() != self.spurset.RFmax):
self.plot.setAxisScale(xaxis, self.spurset.RFmin,
self.spurset.RFmax)
if (yscale.lowerBound() != -self.spurset.dspan/2 or
yscale.upperBound() != self.spurset.dspan/2):
self.plot.setAxisScale(yaxis, -self.spurset.dspan/2,
self.spurset.dspan/2)
self.plot.replot()
def mkline(self, xdata, ydata, style=('black','-'), title=''):
line = QwtPlotCurve(title)
if title is '':
# don't display it in the legend
# kind of ugly, that the title variable is doing double duty
line.setItemAttribute(QwtPlotItem.Legend, False)
pen = self.getPen(*style)
line.setPen(pen)
line.setRenderHint(QwtPlotItem.RenderAntialiased)
line.setData(xdata, ydata)
return line
def add_line(self, line):
line.attach(self.plot)
def del_line(self, line):
line.detach()
def legend(self):
return self.plot.legend()
def _xval(self, pos):
# from a QPoint referring to a pixel on the plot, find the x value
return self.plot.invTransform(xaxis, pos.x())
def _yval(self, pos):
# from a QPoint referring to a pixel on the plot, find the y value
return self.plot.invTransform(yaxis, pos.y())
def onpick(self, pos):
# for now, we only worry about picking the two vertical lines of the
# front-end filter parallelogram. Other clicks are no-ops.
if abs(pos.x() - self.plot.transform(xaxis, self.fef.start)) <= 10:
# TODO check pos.y() as well
self._picked_obj = self.fef.startline
self.pick(self.fef.startline, self._xval(pos), self._yval(pos))
elif abs(pos.x() - self.plot.transform(xaxis, self.fef.stop)) <= 10:
self._picked_obj = self.fef.stopline
#.........这里部分代码省略.........
示例2: Ui_MainWindow
# 需要导入模块: from PyQt4.Qwt5 import QwtPlot [as 别名]
# 或者: from PyQt4.Qwt5.QwtPlot import canvas [as 别名]
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(847, 480)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.horizontalLayout_2 = QtGui.QHBoxLayout(self.centralwidget)
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
#Tworzenie zakładek
self.tabs = QtGui.QTabWidget(self.centralwidget)
#Główny wykre
self.plot = QwtPlot(self.centralwidget)
self.plot.setObjectName(_fromUtf8("plot"))
self.plot.setAxisScale(self.plot.yLeft, -20, 80)
self.plot.setAutoFillBackground(True)
#self.plot.setPalette(Qt.Qt.black)
self.plot.setCanvasBackground(Qt.Qt.black)
self.grid = QwtPlotGrid()
'''self.Yscale = QwtScaleDiv()
self.Yscale.setInterval(10)
self.Xscale = QwtScaleDiv()
self.Xscale.setInterval(10)
self.grid.setYDiv(self.YScale)
self.grid.setXDiv(self.Xscale)'''
self.grid.setMajPen(Qt.Qt.gray)
self.grid.attach(self.plot)
self.tabs.addTab(self.plot, "Spectrum")
self.curve = QwtPlotCurve('')
self.curve.setPen(Qt.Qt.yellow)
self.curve.attach(self.plot)
self.hold_curve = QwtPlotCurve('')
self.hold_curve.setPen(Qt.Qt.red)
self.peak_marker = QwtPlotMarker()
self.symbol = QwtSymbol(QwtSymbol.DTriangle, QtGui.QBrush(Qt.Qt.red), QtGui.QPen(Qt.Qt.red), QtCore.QSize(10,10))
self.peak_marker.setSymbol(self.symbol)
self.peak_marker.setLabelAlignment(Qt.Qt.AlignTop)
self.sybmol_2 = QwtSymbol(QwtSymbol.DTriangle, QtGui.QBrush(Qt.Qt.red), QtGui.QPen(Qt.Qt.white), QtCore.QSize(10,10))
self.marker_1 = QwtPlotMarker()
self.marker_1.setSymbol(self.sybmol_2)
self.marker_1.setLabelAlignment(Qt.Qt.AlignTop)
self.marker_2 = QwtPlotMarker()
self.marker_2.setSymbol(self.sybmol_2)
self.marker_2.setLabelAlignment(Qt.Qt.AlignTop)
self.marker_3 = QwtPlotMarker()
self.marker_3.setSymbol(self.sybmol_2)
self.marker_3.setLabelAlignment(Qt.Qt.AlignTop)
self.marker_4 = QwtPlotMarker()
self.marker_4.setSymbol(self.sybmol_2)
self.marker_4.setLabelAlignment(Qt.Qt.AlignTop)
self.delta_marker = QwtPlotMarker()
self.delta_marker.setSymbol(self.sybmol_2)
self.delta_marker.setLabelAlignment(Qt.Qt.AlignTop)
self.markers = [self.marker_1, self.marker_2, self.marker_3, self.marker_4]
self.save_curve_1 = QwtPlotCurve('')
self.save_curve_1.setPen(Qt.Qt.green)
self.save_curve_2 = QwtPlotCurve('')
self.save_curve_2.setPen(Qt.Qt.cyan)
self.save_curve_3 = QwtPlotCurve('')
self.save_curve_3.setPen(Qt.Qt.magenta)
self.saved_curves = [self.save_curve_1, self.save_curve_2, self.save_curve_3]
#Wykres waterfall
'''self.plot_2 = QwtPlot(self.centralwidget)
self.plot_2.setObjectName(_fromUtf8("plot_2"))
self.waterfall = QwtPlotSpectrogram()
self.waterfall.attach(self.plot_2)
self.colorMap = QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red)
self.scaleColors(80)
self.waterfall.setColorMap(self.colorMap)
#self.waterfallData = QwtRasterData()
#self.tabs.addTab(self.plot_2, "Waterfall")'''
self.verticalLayout.addWidget(self.tabs)
self.picker = QwtPlotPicker(QwtPlot.xBottom,
QwtPlot.yLeft,
QwtPicker.PointSelection | QwtPicker.DragSelection,
QwtPlotPicker.CrossRubberBand,
QwtPicker.AlwaysOn,
self.plot.canvas())
self.picker.setTrackerPen(Qt.Qt.white)
self.picker.setRubberBandPen(Qt.Qt.gray)
self.freqBox = QtGui.QGroupBox(self.centralwidget)
self.freqBox.setObjectName(_fromUtf8("freqBox"))
self.verticalLayout_3 = QtGui.QVBoxLayout(self.freqBox)
#.........这里部分代码省略.........