save matplotlib figure as array

Solutions on MaxInterview for save matplotlib figure as array by the best coders in the world

showing results for - "save matplotlib figure as array"
Tiphaine
14 Oct 2016
1fig = plt.figure()
2ax= fig.add_subplot(111)
3
4plt.plot(your_data)
5
6# turn antialiasing off for lines
7plt.setp([ax.get_xticklines() + ax.get_yticklines() + ax.get_xgridlines() + ax.get_ygridlines()],antialiased=False)
8# turn antialiasing off for text
9mpl.rcParams['text.antialiased']=False
10
11fig.canvas.draw()
12
13array = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
14array = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))