save matplotlib figure as array code example
Example: save matplotlib figure as array
fig = plt.figure()
ax= fig.add_subplot(111)
plt.plot(your_data)
# turn antialiasing off for lines
plt.setp([ax.get_xticklines() + ax.get_yticklines() + ax.get_xgridlines() + ax.get_ygridlines()],antialiased=False)
# turn antialiasing off for text
mpl.rcParams['text.antialiased']=False
fig.canvas.draw()
array = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
array = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))