title: Matplotlib figure to image as a numpy array
body: <p>I'm trying to get a numpy array image from a Matplotlib figure and I'm currently doing it by saving to a file, then reading the file back in, but I feel like there has to be a better way.  Here's what I'm doing now:</p>
  
  <pre><code>from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
  from matplotlib.figure import Figure
  
  fig = Figure()
  canvas = FigureCanvas(fig)
  ax = fig.gca()
  
  ax.text(0.0,0.0,"Test", fontsize=45)
  ax.axis('off')
  
  canvas.print_figure("output.png")
  image = plt.imread("output.png")
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>image = np.fromstring( canvas.tostring_rgb(), dtype='uint8' )
  </code></pre>
  
  <p>from an example I found but it gives me an error saying that 'FigureCanvasAgg' object has no attribute 'renderer'.</p>