Embedding plot in graphicsView in PyQt5

3,497 views
Skip to first unread message

degrou...@gmail.com

unread,
Jun 23, 2017, 7:48:21 PM6/23/17
to pyqtgraph
I did this part promoting “PlotWidget” :

1. In Designer, create a QGraphicsView widget (“Graphics View” under the “Display Widgets” category).
2. Right-click on the QGraphicsView and select “Promote To...”.
3. Under “Promoted class name”, enter the class name you wish to use (“PlotWidget”, “GraphicsLayoutWidget”, etc).
4. Under “Header file”, enter “pyqtgraph”.
5. Click “Add”, then click “Promote”.

Now, I am trying to plot in the GraphicsView.

       
        self.pushButton.clicked.connect(self.btn_clk)
       
       
MainWindow.show()
   
def btn_clk(self):
        L
= [1,2,3,4,5]
        pg
.plot(L)


If I use this above, the plot shows up in a new window.

My question is: how can I plot in the GraphicsView instead of a new window.

I tried several different variations of getPlotItem(), but it didn't work.

Thanks very much.

Cheers,

Joe

Christopher Mullins

unread,
Jul 27, 2017, 2:33:16 PM7/27/17
to pyqtgraph
I adjusted a simple example for this and posted it as a github gist [1].  It consists of the .ui file and the python script with the __main__ function and application class.  First you want to add a plot to your graphicsView, and then make sure you refer to your graphicsView existing in your QMainWindow when calling plot(), not pg.plot().  Let me know if you have any questions!

[1] https://gist.github.com/chrismullins/0b9599bee313e52cdc95115af2492fe7

degrou...@gmail.com

unread,
Aug 19, 2017, 11:33:19 PM8/19/17
to pyqtgraph
Hi Christopher,

Thanks so much! This works. I appreciate your help very much.

Can you please let me know how I can use this for other type of plots i.e. BarGraph or ScattepPlot?

When I  try to addItem() to use other kind of plots, I am kind of lost.

Please kindly point me in the right direction.

Thanks again.

Cheers,

Joe
Reply all
Reply to author
Forward
0 new messages