title: Plotting matplotlib figure inside QWidget using Qt Designer form and PyQt5
body: <p>I don't understand the best way to link a matplotlib figure to a form created from Qt Designer.  I have a form I created in QtDesigner and then compiled to python through pyuic5.  My main program is:</p>
  
  <pre><code>import app_framework as af
  import matplotlib
  from PyQt5 import QtWidgets
  import sys
  
  matplotlib.use('Qt5Agg')
  
  app = QtWidgets.QApplication(sys.argv)
  form = af.MyApp()
  form.show()
  app.exec_()
  </code></pre>
  
  <p>where myApp calls the app_framework.py form created from Qt Designer then converted by pyuic5 (design.py):</p>
  
  <pre><code>from PyQt5.QtWidgets import QApplication, QMainWindow
  import design
  
  class MyApp(QMainWindow, design.Ui_mainWindow):
     def __init(self):
         super(self.__class__, self).__init__()
         &lt;button initializations&gt;
         &lt;function definitions for button callbacks&gt;
  </code></pre>
  
  <p>I'm confused as to where in this framework I can link a matplotlib figure to a premade empty widget in QtDesigner, or something of that sort, so that I can plot new data in the GUI window as things happen (text entered, button push, etc.)</p>
  
  <p>I've found some threads here on <a href="https://stackoverflow.com/questions/36222998/drawing-in-a-matplotlib-widget-in-qtdesigner">SO</a> and <a href="http://matplotlib.org/examples/user_interfaces/embedding_in_qt5.html" rel="noreferrer">matplotlib's site</a>, but I'm not sure I understand the correct process for creating the space for this widget in the Qt Designer form then linking a plot, and/or creating a widget post hoc and then linking and plotting.</p>
  
  <p>What I've done so far is create an empty QWidget inside Qt Creator and then after pyuic5 compile, I alter the design.py file as follows:</p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  
  # **** ADDED THIS
  from matplotlib.figure import Figure
  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as Canvas
  # **** 
  
  class Ui_mainWindow(object):
      def setupUi(self, mainWindow):
          &lt;mainWindow setup stuff&gt;
          self.centralwidget = QtWidgets.QWidget(mainWindow)
  
          # ****ALTERED THIS FROM self.plotWidget = QtWidgets.QWidget(self.centralWidget)
          self.plotWidget = MplWidget(self.centralWidget)
          # ***** 
  
          self.plotWidget.setGeometry(QtCore.QRect(20, 250, 821, 591))
          self.plotWidget.setObjectName("plotWidget")
  
    # **** ADDED THIS 
  class MplCanvas(Canvas):
      def __init__(self):
          self.fig = Figure()
          self.ax = self.fig.add_subplot(111)
          Canvas.__init__(self, self.fig)
          Canvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
          Canvas.updateGeometry(self)
  
  
  class MplWidget(QtWidgets.QWidget):
      def __init__(self, parent=None):
          QtWidgets.QWidget.__init__(self, parent)
          self.canvas = MplCanvas()
   # ***********
  </code></pre>
  
  <p>and then app_framework.py as:</p>
  
  <pre><code>from PyQt5.QtWidgets import QApplication, QMainWindow
  import design
  
  class MyApp(QMainWindow, design.Ui_mainWindow):
     def __init(self):
         super(self.__class__, self).__init__()
         self.setupUi(self)
         self.pushButton_plotData.clicked.connect(self.plot_data)
  
      def plot_data(self):
          x=range(0, 10)
          y=range(0, 20, 2)
          self.plotWidget.canvas.ax.plot(x, y)
          self.plotWidget.canvas.draw()
  </code></pre>
  
  <p>I thought this would work, but when I click the plot push button, nothing happens.  It doesn't lock up, it just doesn't plot anything.  I'm guessing I'm missing something fundamental for plotting a matplotlib figure and/or canvas in this empty widget.</p>