Hi,
I have gone through the Examples coming with pyqtgraph, but I didn’t get the idea of getting a simple plot using pyqtgraph.GraphicsView For two days I am sitting with this code without any result. Please help. This is the code:
#! /usr/bin/python
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
import numpy as np
import pyqtgraph as pg
class GraphDisplay(QtGui.QMainWindow):
def __init__( self , parent =None):
QtGui.QMainWindow.__init__ (self , parent)
self.setGeometry( 200, 100 , 800, 300 )
self.dataPlot = np.cos(np.linspace(0, 2*np.pi , 1000))
self.view = pg.GraphicsView ()
self.graphpaper = pg.ViewBox()
self.view.setCentralWidget(self.graphpaper)
self.graph = pg.PlotItem()
self.graph.plot( self.dataPlot)
self.graphpaper.addItem(self.graph)
def ShowWindow():
app = QtGui.QApplication(sys.argv)
qb = GraphDisplay()
qb.show()
sys.exit(app.exec_())
if __name__ == '__main__':
ShowWindow()
Also please show me the recommended way of using pyqtgraph.GraphicsView
self.view = pg.GraphicsView ()
self.graphpaper = pg.PlotItem()
self.view.setCentralWidget(self.graphpaper)
self.graphpaper.plot( self.dataPlot)
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
Thanks a million Luke,
You
separated the cream from milk. You just changed my understanding of Pyqtgraph. Sorry
to say your code didn’t worked for me. As pointed out by you I sat few minutes
with the link you have given and changed my code. This is my new code ( I
commented the code if someone else want to know how this works ). Luke, please
review my comment, and if something wrong with my understanding please correct
me.
#! /usr/bin/python
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
import numpy as np
import pyqtgraph as pg
class GraphDisplay(QtGui.QMainWindow):
def __init__( self , parent =None):
QtGui.QMainWindow.__init__ (self , parent)
self.setGeometry( QtCore.QRect(200, 100 , 1000, 300 ))
self.dataPlot = np.cos(np.linspace(0, 5 *np.pi , 1000))
#--------------------------------------------------- Create a plot item;
#-------- This is essentially your graph paper where your graph is drawn
self.graph = pg.PlotItem()
#------------- Put your data inside PlotItem to get your actual plotting
self.graph.plot( self.dataPlot)
#------------------------- You are going to show your graph paper inside
#---------------------------------- the GraphicsView widget of Pyqtgraph
self.view = pg.GraphicsView()
#--------------------------- if you are going to use multiple plot items
#--------- in the same graphics view get layout and add items one by one
#--------- for that uncomment bellow codes (1) ,(2) ,(3) and comment (4)
#---------- self.lay = pg.GraphicsLayout() #----(1)
#---------- self.lay.addItem(self.graph) #----(2)
#---------- self.view.setCentralItem(self.lay) #----(3)
#-------------------------------- If you display only one graph use this
self.view.setCentralItem(self.graph) #----(4)
#---------------------------------------- Since we are using QMainWindow
#--------------------------- put our view as CentralWidget in MainWindow
self.setCentralWidget(self.view)
def ShowWindow():
app = QtGui.QApplication(sys.argv)
qb = GraphDisplay()
qb.show()
sys.exit(app.exec_())
if __name__ == '__main__':
ShowWindow()
One more question (not directly connected to pyqtgraph), when using eclipse for editing code imported from pyqtgraph it is not showing certain attributes/methods like pg.PlotItem() or pg.ViewBox() on ‘auto complete’ but it is showing other attribute names like pg.GraphicsView() from the package correctly. Any idea ?
One more question (not directly connected to pyqtgraph), when using eclipse for editing code imported from pyqtgraph it is not showing certain attributes/methods like pg.PlotItem() or pg.ViewBox() on ‘auto complete’ but it is showing other attribute names like pg.GraphicsView() from the package correctly. Any idea ?
Regarding the eclipse problem I found out the solution. If importing pygtgraph still shows unavailable module error, then goto Eclipse -> Preferences -> PyDev -> Interpreter – Python
click the "Forced Builtins" tab, click "New...", type "pyqtgraph", and click "OK".
Now it should show all the modules from pyqtgraph
Courtesy: Alex Bigelow [http://alexstroubleshooting.blogspot.in/2012/05/pyside-in-eclipse.html]