从PyQtGraph版本0.10.0开始,我在图中的TextItems有问题: 我有一个图表(PlotItem)与启用自动缩放和TextItem。在某些情况下,自动缩放会尝试缩放不可伸缩的TextItem。该图表一次又一次地重新调整。 这种情况发生在:
对于我的观点,这个问题在PyQtGraph的0.9.10版本中没有。
案例1的例子:
import PySide
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="auto scaling bug when having a TextItem")
win.resize(1000,500)
win.setWindowTitle("auto scaling bug when having a TextItem")
p1 = win.addPlot(title="Plot with TextItem", y=np.zeros(10))
#p1.plot(y=[100]*10)
ti = pg.TextItem(text="My TextItem", color='r', anchor=(0.0, 1.0), angle=90)
p1.addItem(ti)
ti.setPos(0, 0)
p1.enableAutoRange('y', True)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
案例2的例子:
import PySide
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="auto scaling bug when having a TextItem")
win.resize(1000,150)
win.setWindowTitle("auto scaling bug when having a TextItem")
p1 = win.addPlot(title="Plot with TextItem", y=np.zeros(10))
p1.plot(y=[100]*10)
ti = pg.TextItem(text="My TextItem", color='r', anchor=(0.0, 1.0), angle=90)
p1.addItem(ti)
ti.setPos(0, 0)
p1.enableAutoRange('y', True)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
有没有人有想法(除了回到0.9.10版本)? 提前谢谢!
答案 0 :(得分:1)
哦,我自己找到了一个解决方案:
addItem
方法允许选项ignoreBounds
。当我添加TextItem并将此选项设置为True
时,自动缩放将起作用:
p1.addItem(ti, ignoreBounds = True)
很抱歉在调试之前询问。