'NoneType' object has no attribute 'removeItem'

90 views Asked by At

I want to set axisItems to a PlotItem useing pyqtgraph, and encountered an error while running my code.

Here is my code:

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()

When I run this code, it shows the error as below:

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'

While I tried to set axises when initialzing PlotItem, it succeeded. However, my problem is how to set axises after initialized 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

There are 0 answers