title: Embedding matplotlib graph into pyqt5
body: <p>I've tried using example pieces of code to embed my animated graph of mars and earth orbiting the sun using an _update_plot from pyplot from matplotlib into a PyQt5 GUI.
  There are no examples that use pyplot and I'm really struggling.
  What have I dont wrong here: (?)</p>
  
  <p>Attempt:</p>
  
  <pre><code>import sys
  import time
  
  import numpy as np
  
  from matplotlib.backends.qt_compat import QtCore, QtWidgets, is_pyqt5
  if is_pyqt5():
      from matplotlib.backends.backend_qt5agg import (
          FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
  else:
      from matplotlib.backends.backend_qt4agg import (
          FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
  from matplotlib.figure import Figure
  
  
  class ApplicationWindow(QtWidgets.QMainWindow):
      def __init__(self):
          super().__init__()
          self._main = QtWidgets.QWidget()
          self.setCentralWidget(self._main)
          layout = QtWidgets.QVBoxLayout(self._main)
  
          static_canvas = FigureCanvas(Figure(figsize=(5, 3)))
          layout.addWidget(static_canvas)
          self.addToolBar(NavigationToolbar(static_canvas, self))
  
          dynamic_canvas = FigureCanvas(Figure(figsize=(5, 3)))
          layout.addWidget(dynamic_canvas)
          self.addToolBar(QtCore.Qt.BottomToolBarArea,
                          NavigationToolbar(dynamic_canvas, self))
  
          self._static_ax = static_canvas.figure.subplots()
          t = np.linspace(0, 10, 501)
          self._static_ax.plot(t, np.tan(t), ".")
  
          self._dynamic_ax = dynamic_canvas.figure.subplots()
          self._timer = dynamic_canvas.new_timer(
              100, [(self._update_canvas, (), {})])
          self._timer.start()
  
      def _update_canvas(self):
          scat = scat.set_offsets(([math.cos(math.radians(i))*7.5, math.sin(math.radians(i))*7.5], [math.cos(math.radians(i/2))*9, math.sin(math.radians(i/2))*9], [0, 0]))
          anim = self.animation.FuncAnimation(fig, scat, fargs = (fig, scat, l,l2),
                                 frames = 720, interval = 10)
  
  
  
  if __name__ == "__main__":
      qapp = QtWidgets.QApplication(sys.argv)
      app = ApplicationWindow()
      app.show()
      qapp.exec_()
  </code></pre>
  
  <p>the Original code I'm trying to embed is this:</p>
  
  <pre><code>import math
  import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  import numpy as np
  
  def _update_plot(i, fig, scat): 
          M = ((math.sin(math.radians(i))*7.5)-(math.sin(math.radians(i/2))*9))/((math.cos(math.radians(i))*7.5)-(math.cos(math.radians(i/2))*9))
          g = M*(15-(math.cos(math.radians(i/2))*9))+(math.sin(math.radians(i/2))*9)
  
          scat.set_offsets(([math.cos(math.radians(i))*7.5, math.sin(math.radians(i))*7.5], [math.cos(math.radians(i/2))*9, math.sin(math.radians(i/2))*9], [0, 0]))
          return [scat]
  
  fig = plt.figure()
  x = [0]
  y = [0]
  
  ax = fig.add_subplot(111)
  ax.set_aspect('equal')
  ax.grid(True, linestyle = '-', color = '0.10')
  ax.set_xlim([-15, 15])
  ax.set_ylim([-15, 15])
  
  scat = plt.scatter(x, y, c = x, zorder=3)
  scat.set_alpha(0.8)
  
  anim = animation.FuncAnimation(fig, _update_plot, fargs = (fig, scat),
                                 frames = 720, interval = 10)
  
  plt.show()
  </code></pre>
  
  <p>Any help/advice is greatly appreciated.</p>