0
我正在創建一個PyQt5桂,我正在使用PyQtGraph繪製一些數據。這是一個最小的,完整的,可驗證的示例腳本,它非常類似於我擁有的結構。PyQt5 gui與PyQtGraph情節:顯示右側的y軸
import sys
from PyQt5.QtWidgets import (QWidget, QGridLayout, QApplication)
import pyqtgraph as pg
from pyqtgraph import QtCore, QtGui
class CustomPlot(pg.GraphicsObject):
def __init__(self, data):
pg.GraphicsObject.__init__(self)
self.data = data
print(self.data)
self.generatePicture()
def generatePicture(self):
self.picture = QtGui.QPicture()
p = QtGui.QPainter(self.picture)
p.setPen(pg.mkPen('w', width=1/2.))
for (t, v) in self.data:
p.drawLine(QtCore.QPointF(t, v-2), QtCore.QPointF(t, v+2))
p.end()
def paint(self, p, *args):
p.drawPicture(0, 0, self.picture)
def boundingRect(self):
return QtCore.QRectF(self.picture.boundingRect())
class Window(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.simpleplot()
def initUI(self):
self.guiplot = pg.PlotWidget()
layout = QGridLayout(self)
layout.addWidget(self.guiplot, 0,0)
def simpleplot(self):
data = [
(1., 10),
(2., 13),
(3., 17),
(4., 14),
(5., 13),
(6., 15),
(7., 11),
(8., 16)
]
pgcustom = CustomPlot(data)
self.guiplot.addItem(pgcustom)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
y軸是對劇情的左側,但我想將其移動到右邊的圖表。我已經嘗試了一些東西,但我找不到可以實現此目的的選項或方法的對象(QtGui.QPainter,GraphicObject等)。
感謝您的提示。我瀏覽了PyQt5教程並閱讀了PyQtGraph的相關文檔,但錯過了您提到的部分, – Spinor8