import matplotlib.pyplot as plt import numpy as np
# Make a random plot... fig = plt.figure() fig.add_subplot(111)
# If we haven't already shown or saved the plot, then we need to # draw the figure first... fig.canvas.draw()
# Now we can save it to a numpy array. data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='') data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))