title: Function for subplots for real time plotting
body: <p>I have a code which gives me 4 individual live plotting graphs for 4 different sensors. But, I want them in a single frame using subplots. Pasting 2 pieces of code which are plotting my graphs. How should I modify them for my output to be a subplots of 4 live graphs.</p>
  <pre><code>def makeFigure(xLimit, yLimit, title):
      xmin, xmax = xLimit
      ymin, ymax = yLimit
      fig = plt.figure()
      ax = plt.axes(xlim=(xmin, xmax), ylim=(int(ymin - (ymax - ymin) / 10), int(ymax + (ymax - ymin) / 10)))
      ax.set_title(title)
      ax.set_xlabel(&quot;Time&quot;)
      ax.set_ylabel(&quot;Detector Output&quot;)
      ax.grid(True)
      return fig, ax
  </code></pre>
  <pre><code>    pltInterval = 50  # Period at which the plot animation updates [ms]
      lineLabelText = ['Detector A', 'Detector B', 'Detector C', 'Detector D']
      title = ['Detector A', 'Detector B', 'Detector C', 'Detector D']
      xLimit = [(0, maxPlotLength), (0, maxPlotLength), (0, maxPlotLength), (0, maxPlotLength)]
      yLimit = [(-1, 1), (-1, 1), (-1, 1), (-1, 1)]
      style = ['r-', 'g-', 'b-', 'y-']  # linestyles for the different plots
      anim = []
      for i in range(numPlots):
          fig, ax = makeFigure(xLimit[i], yLimit[i], title[i])
          lines = ax.plot([], [], style[i], label=lineLabelText[i])[0]
          timeText = ax.text(0.50, 0.95, '', transform=ax.transAxes)
          lineValueText = ax.text(0.50, 0.90, '', transform=ax.transAxes)
  
          anim.append(
              animation.FuncAnimation(fig, s.getSerialData, fargs=(lines, lineValueText, lineLabelText[i], timeText, i),
                                      interval=pltInterval))  # fargs has to be a tuple
  
          plt.legend(loc=&quot;upper left&quot;)
      plt.show()
  
      s.close()
  </code></pre>