importmatplotlibimportmatplotlib.pyplotaspltimportnumpyasnpimportsysimporttimeitfrommatplotlib.backends.backend_pdfimportPdfPagesmatplotlib.rcParams.update({'font.size':6})# Dimensions for any n-rows x m-cols array of subplots / pg.n,m=4,5# Don't forget to indent after the with statementwithPdfPages('auto_subplotting.pdf')aspdf:# Let's time the execution required to create and save# each full page of subplots to the pdfstart_time=timeit.default_timer()# Before beginning the iteration through all the data,# initialize the layout for the plots and create a# representation of the subplots that can be easily# iterated over for knowing when to create the next page# (and also for custom settings like partial axes labels)f,axarr=plt.subplots(n,m,sharex='col',sharey='row')arr_ij=[(x,y)forx,yinnp.ndindex(axarr.shape)]subplots=[axarr[index]forindexinarr_ij]# To conserve needed plotting real estate,# only label the bottom row and leftmost subplots# as determined automatically using n and msplot_index=0fors,splotinenumerate(subplots):splot.set_ylim(0,.15)splot.set_xlim(0,50)last_row=(n*m-s
python多子图导出至pdf_python将多个子图数字保存为pdf
最新推荐文章于 2023-03-08 16:29:26 发布