添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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!

If i use pg.bargraphitem i get the message Painter path exceeds +/-32767 pixels. No Tracelog or anything else - i allready tried with a lot of prints to find out where it starts and ends, but with every mouse move across the plotwindow this message occures on the terminal, but only when the bargraphitem is added to the plotwindow, every other plot (like when i plot it like a trace into this window) works ... I'm really not getting any further – Saibot Robot Apr 26, 2022 at 17:24 I just tried to make a curveItem instead of a bargraphitem - the filling between the y or x axis and the curveitem seem to Trigger the same "print Warning" with the "Painter path exceeds +/- bla bla bla ..." (idk what i should call this strange Warning Message without tracelog or anything else) - Maybe the bargraphitem uses the same way to fill the space between the curve and the axis ... All in all i just ploted the values as a curve - does not look so pretty as a histogram but works for the moment – Saibot Robot May 25, 2022 at 16:47

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.