在pyqtgraph中使用多轴时,下拉框中缺少轴

2024-04-25 17:31:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下问题:创建多个视口时,每个视口都有一个轴,无法使用鼠标右键从左侧所有可用轴中选择->;y轴->;链接轴。由PlotWidget自动创建的ViewBox中的可用轴不可用于选择:“链接轴:”下拉框中仅显示“轴1”和“轴2”。你知道吗

DropDownbox with missing axis:

我做错什么了?你知道吗

请参阅下面我使用的代码:

from pyqtgraph.widgets.PlotWidget import PlotWidget
import pyqtgraph as pg
import PyQt4

class Graph(PlotWidget):
  def __init__(self, parent=None):
    PlotWidget.__init__(self, parent)
    self._viewBoxes = [self.plotItem.getViewBox()]
    self._viewBoxes[0].register("axis 0")
    for i in xrange(2):
      vb = pg.ViewBox(name="axis %s" %(i+1))
      self.plotItem.scene().addItem(vb)
      vb.setXLink(self.plotItem)
      self._viewBoxes.append(vb)
    self._axes = [pg.AxisItem('left') for _ in xrange(3)]
    for c in zip(self._viewBoxes, self._axes):
      vb, ax = c
      ax.linkToView(vb)

    self._curves = [self.plotItem.plot()]
    for vb in self._viewBoxes[1:]:
      plotDataItem = pg.PlotDataItem()
      vb.addItem(plotDataItem)
      self._curves.append(plotDataItem)

    for p in self._viewBoxes[1:]:
      p.setGeometry(self.plotItem.vb.sceneBoundingRect())
      p.linkedViewChanged(self.plotItem.vb, p.XAxis)

    self._curves[0].setData(x=[1,2,3,4],y=[0,4,0,4], pen="b")
    self._curves[1].setData(x=[1,2,3,4],y=[0,1,2,1], pen="y")
    self._curves[2].setData(x=[1,2,3,4],y=[0,-8,8,7], pen="r")

app = PyQt4.QtGui.QApplication([])
graph1 = Graph()
graph1.show()
app.exec_()

Tags: inimportselfforpgvbaxispen