title: Embedding pyqtgraph into tab widget Pyqt
body: <p>I am bit new to Pyqt4 and pyqtgraph. I have tab widget with me and I want to add pyqtgraph into tab widget, so that this graph will be displayed inside (tab1) widget. Can any one tell me how can I do it? where should I add my pyqtgrapgh code in tab widget code. Corresponding code for tab widget and pyqtgraph is as follows.
  code for tab widget :</p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  
  try:
      _fromUtf8 = QtCore.QString.fromUtf8
  except AttributeError:
      _fromUtf8 = lambda s: s
  
  class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
          MainWindow.setObjectName(_fromUtf8("MainWindow"))
          MainWindow.resize(728, 507)
          self.centralWidget = QtGui.QWidget(MainWindow)
          self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
          self.tabWidget = QtGui.QTabWidget(self.centralWidget)
          self.tabWidget.setGeometry(QtCore.QRect(20, 70, 691, 371))
          self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
          self.tab = QtGui.QWidget()
          self.tab.setObjectName(_fromUtf8("tab"))
          self.tabWidget.addTab(self.tab, _fromUtf8(""))
          self.tab_2 = QtGui.QWidget()
          self.tab_2.setObjectName(_fromUtf8("tab_2"))
          self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
          self.label = QtGui.QLabel(self.centralWidget)
          self.label.setGeometry(QtCore.QRect(320, 20, 71, 41))
          font = QtGui.QFont()
          font.setPointSize(14)
          self.label.setFont(font)
          self.label.setObjectName(_fromUtf8("label"))
          MainWindow.setCentralWidget(self.centralWidget)
          self.menuBar = QtGui.QMenuBar(MainWindow)
          self.menuBar.setGeometry(QtCore.QRect(0, 0, 728, 21))
          self.menuBar.setObjectName(_fromUtf8("menuBar"))
          MainWindow.setMenuBar(self.menuBar)
          self.mainToolBar = QtGui.QToolBar(MainWindow)
          self.mainToolBar.setObjectName(_fromUtf8("mainToolBar"))
          MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
          self.statusBar = QtGui.QStatusBar(MainWindow)
          self.statusBar.setObjectName(_fromUtf8("statusBar"))
          MainWindow.setStatusBar(self.statusBar)
  
          self.retranslateUi(MainWindow)
          self.tabWidget.setCurrentIndex(0)
          QtCore.QMetaObject.connectSlotsByName(MainWindow)
  
      def retranslateUi(self, MainWindow):
          MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
          self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("MainWindow", "plot_1", None, QtGui.QApplication.UnicodeUTF8))
          self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("MainWindow", "plot_2", None, QtGui.QApplication.UnicodeUTF8))
          self.label.setText(QtGui.QApplication.translate("MainWindow", "  PLOTS", None, QtGui.QApplication.UnicodeUTF8))
  
  
  if __name__ == "__main__":
      import sys
      app = QtGui.QApplication(sys.argv)
      MainWindow = QtGui.QMainWindow()
      ui = Ui_MainWindow()
      ui.setupUi(MainWindow)
      MainWindow.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>Code for pyqtgrapgh:</p>
  
  <pre><code>from pyqtgraph.Qt import QtGui, QtCore
  import numpy as np
  import pyqtgraph as pg
  
  app = QtGui.QApplication([])
  
  win = pg.GraphicsWindow(title="Basic plotting examples")
  win.resize(1000,600)
  win.setWindowTitle('pyqtgraph example: Plotting')
  
  # Enable antialiasing for prettier plots
  pg.setConfigOptions(antialias=True)
  
  p6 = win.addPlot(title="My Plot")
  curve = p6.plot(pen='r')
  data = np.random.normal(size=(10,10))
  ptr = 0
  def update():
      global curve, data, ptr, p6
      curve.setData(data[ptr%10])
      if ptr == 0:
          p6.enableAutoRange('xy', False)  ## stop auto-scaling after the first data set is plotted
      ptr += 1
  timer = QtCore.QTimer()
  timer.timeout.connect(update)
  timer.start(500)
  
  ## Start Qt event loop unless running in interactive mode or using pyside.
  if __name__ == '__main__':
      import sys
      if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
          QtGui.QApplication.instance().exec_()
  </code></pre>
  
  <p>I have tried the way you have suggested me but now I am getting two windows popped up with none of them showing me the plots. I got one plotWidget in my tab Widget but how can I get rid of other plot window? Will you please tell me where I am exactly going wrong. The modified code which I am trying is as follows.</p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  from pyqtgraph.Qt import QtGui, QtCore
  import numpy as np
  import pyqtgraph as pg
  
  try:
      _fromUtf8 = QtCore.QString.fromUtf8
  except AttributeError:
      _fromUtf8 = lambda s: s
  
  class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
          global win,curve
          MainWindow.setObjectName(_fromUtf8("MainWindow"))
          MainWindow.resize(728, 507)
          self.centralWidget = QtGui.QWidget(MainWindow)
          self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
          self.tabWidget = QtGui.QTabWidget(self.centralWidget)
          self.tabWidget.setGeometry(QtCore.QRect(20, 70, 691, 371))
          self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
          self.tab = QtGui.QWidget()
          self.tab.setObjectName(_fromUtf8("tab"))
          ###
          self.tabWidget.insertTab(3, self.win, "plot")
          ###
          self.tabWidget.addTab(self.tab, _fromUtf8(""))
          self.tab_2 = QtGui.QWidget()
          self.tab_2.setObjectName(_fromUtf8("tab_2"))
          self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
          self.label = QtGui.QLabel(self.centralWidget)
          self.label.setGeometry(QtCore.QRect(320, 20, 71, 41))
          font = QtGui.QFont()
          font.setPointSize(14)
          self.label.setFont(font)
          self.label.setObjectName(_fromUtf8("label"))
          MainWindow.setCentralWidget(self.centralWidget)
          self.menuBar = QtGui.QMenuBar(MainWindow)
          self.menuBar.setGeometry(QtCore.QRect(0, 0, 728, 21))
          self.menuBar.setObjectName(_fromUtf8("menuBar"))
          MainWindow.setMenuBar(self.menuBar)
          self.mainToolBar = QtGui.QToolBar(MainWindow)
          self.mainToolBar.setObjectName(_fromUtf8("mainToolBar"))
          MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
          self.statusBar = QtGui.QStatusBar(MainWindow)
          self.statusBar.setObjectName(_fromUtf8("statusBar"))
          MainWindow.setStatusBar(self.statusBar)
  
          self.retranslateUi(MainWindow)
          self.tabWidget.setCurrentIndex(0)
          QtCore.QMetaObject.connectSlotsByName(MainWindow)
  
  def retranslateUi(self, MainWindow):
      MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
      self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("MainWindow", "plot_1", None, QtGui.QApplication.UnicodeUTF8))
      self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("MainWindow", "plot_2", None, QtGui.QApplication.UnicodeUTF8))
      self.label.setText(QtGui.QApplication.translate("MainWindow", "  PLOTS", None, QtGui.QApplication.UnicodeUTF8))
  
  win = pg.GraphicsWindow(title="Basic plotting examples")
  win.resize(1000,600)
  win.setWindowTitle('pyqtgraph example: Plotting')
  
  # Enable antialiasing for prettier plots
  pg.setConfigOptions(antialias=True)
  
  p6 = win.addPlot(title="My Plot")
  curve = p6.plot(pen='r')
  data = np.random.normal(size=(10,10))
  ptr = 0
  def update():
      global curve, data, ptr, p6
      curve.setData(data[ptr%10])
      if ptr == 0:
          p6.enableAutoRange('xy', False)  ## stop auto-scaling after the first data set is plotted
      ptr += 1
  timer = QtCore.QTimer()
  timer.timeout.connect(update)
  timer.start(500)
  
  
  
  if __name__ == "__main__":
      import sys
      if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
      QtGui.QApplication.instance().exec_()
      app = QtGui.QApplication(sys.argv)
      MainWindow = QtGui.QMainWindow()
      ui = Ui_MainWindow()
      ui.setupUi(MainWindow)
      MainWindow.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>I am also getting an error like - 
  NameError: global name 'curve' is not defined
  Segmentation fault (core dumped)
  Will you please tell me how to get rid of this error.</p>