NoneType'对象没有'removeItem'属性
我想在使用pyqtgraph的时候给PlotItem设置轴项,但在运行我的代码时遇到了错误。
这是我的代码:
import pyqtgraph as pg
x = [1,2,3,4,5,6,7,8,9,10]
y = [1,2,3,4,5,6,7,8,9,10]
app = pg.mkQApp("app")
win = pg.GraphicsLayoutWidget()
plot_item = pg.PlotItem()
plot_item.setAxisItems(axisItems={'bottom':pg.AxisItem('bottom')}) # error occurs here
plot_item.plot(x, y)
win.addItem(plot_item)
win.show()
app.exec()
当我运行这段代码时,出现了如下错误:
Traceback (most recent call last):
File "E:\Workspace\Python\VNPY-master\examples\candle_chart\tick\item\test.py", line 10, in <module>
plot_item.setAxisItems(axisItems={'bottom':pg.AxisItem('bottom')}) # error occurs here
File "E:\home\.conda\envs\Python310\lib\site-packages\pyqtgraph\graphicsItems\PlotItem\PlotItem.py", line 312, in setAxisItems
oldAxis.scene().removeItem(oldAxis)
AttributeError: 'NoneType' object has no attribute 'removeItem'
我在初始化PlotItem的时候尝试设置轴项是成功的。但是,我的问题是,如何在初始化PlotItem之后再设置轴项呢?
import pyqtgraph as pg
x = [1,2,3,4,5,6,7,8,9,10]
y = [1,2,3,4,5,6,7,8,9,10]
app = pg.mkQApp("app")
win = pg.GraphicsLayoutWidget()
plot_item = pg.PlotItem(axisItems={'bottom':pg.AxisItem('bottom')}) #run successfully
plot_item.plot(x, y)
win.addItem(plot_item)
win.show()
app.exec()
0 个回答
暂无回答