python - Save a subplot in matplotlib -


is possible save (to png) individual subplot in matplotlib figure? lets have

import pylab p ax1 = subplot(121) ax2 = subplot(122) ax.plot([1,2,3],[4,5,6]) ax.plot([3,4,5],[7,8,9]) 

is possible save each of 2 subplots different files or @ least copy them separately new figure save them?

i using version 1.0.0 of matplotlib on rhel 5.

thanks,

robert

while @eli quite correct there isn't of need it, possible. savefig takes bbox_inches argument can used selectively save portion of figure image.

here's quick example:

import matplotlib.pyplot plt import matplotlib mpl import numpy np  # make example plot 2 subplots... fig = plt.figure() ax1 = fig.add_subplot(2,1,1) ax1.plot(range(10), 'b-')  ax2 = fig.add_subplot(2,1,2) ax2.plot(range(20), 'r^')  # save full figure... fig.savefig('full_figure.png')  # save portion _inside_ second axis's boundaries extent = ax2.get_window_extent().transformed(fig.dpi_scale_trans.inverted()) fig.savefig('ax2_figure.png', bbox_inches=extent)  # pad saved area 10% in x-direction , 20% in y-direction fig.savefig('ax2_figure_expanded.png', bbox_inches=extent.expanded(1.1, 1.2)) 

the full figure: full example figure


area inside second subplot: inside second subplot


area around second subplot padded 10% in x-direction , 20% in y-direction: full second subplot


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -