Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
i have a problem with the pyqtgraph PlotCurveItem() function.
This is the code. The plot1 is shown in another part of the program.
vals = np.random.random(size=100)*0.8
y, x = np.histogram(vals,bins=np.linspace(min(vals),max(vals),num=50)
curve = pg.PlotCurveItem()
curve.setData(x,y,stepMode="center")
self.plot1.addItem(curve)
I want to make a histogram with stepMode="center" but there occure two error codes which contradict each other as one needs the shapes of x and y to be same and the other one says they need to be len(x)=len(y)+1.
When i make the length of array x as mentioned i will get alternately either one or the other error:
- Error1
File ".../lib/python3.8/site-packages/pyqtgraph/widgets/GraphicsView.py", line 142, in paintEvent
return super().paintEvent(ev)
File ".../lib/python3.8/site-packages/pyqtgraph/debug.py", line 124, in w
printExc('Ignored exception:')
--- exception caught here ---
File ".../lib/python3.8/site-packages/pyqtgraph/debug.py", line 122, in w
func(*args, **kwds)
File ".../lib/python3.8/site-packages/pyqtgraph/graphicsItems/PlotCurveItem.py", line 768, in paint
self.paintGL(p, opt, widget)
File ".../lib/python3.8/site-packages/pyqtgraph/graphicsItems/PlotCurveItem.py", line 884, in paintGL
pos[:,1] = y
ValueError: could not broadcast input array from shape (49,) into shape (50,)
printExc('Ignored exception:')
- Error2
File ".../lib/python3.8/site-packages/pyqtgraph/graphicsItems/PlotCurveItem.py", line 479, in setData
self.updateData(*args, **kargs)
File ".../lib/python3.8/site-packages/pyqtgraph/graphicsItems/PlotCurveItem.py", line 532, in updateData
raise Exception("len(X) must be len(Y)+1 since stepMode=True (got %s and %s)" % (self.xData.shape, self.yData.shape))
Exception: len(X) must be len(Y)+1 since stepMode=True (got (49,) and (49,))
Thanks for any help!
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.