Why does this code not save my numbers with names?

I draw a few numbers with the following code:

def boxplot_data(self,parameters_file,figure_title):
    data = pandas.read_csv(parameters_file)
    header = data.keys()
    number_of_full_subplots = len(header)/16
    remainder = len(header)-(16*number_of_full_subplots)
    try:
        for i in range(number_of_full_subplots+1):
            fig =plt.figure(i)
            txt = fig.suptitle(figure_title+' (n='+str(len(data[header[0]]))+') '+'Page '+str(i)+' of '+str(number_of_full_subplots),fontsize='20')
            txt.set_text(figure_title+' (n='+str(len(data[header[0]]))+') '+'Page '+str(i)+' of '+str(number_of_full_subplots))
            for j in range(16):
                plt.ioff()
                plt.subplot(4,4,j)
                plt.boxplot(data[header[16*i+j]])
                plt.xlabel('')  
                mng=plt.get_current_fig_manager()
                mng.window.showMaximized()                    
                plt.savefig(str(i)+'.png',bbox_inches='tight',orientation='landscape')
                plt.close(fig)                    
                plt.ion()
    except IndexError:
        txt = fig.suptitle(figure_title+' (n='+str(len(data[header[0]]))+') '+'Page '+str(i)+' of '+str(number_of_full_subplots),fontsize='20')
        txt.set_text(figure_title+' (n='+str(len(data[header[0]]))+') '+'Page '+str(i)+' of '+str(number_of_full_subplots))
        print '{} full figures were created and 1 partially filled \
        figure containing {} subplots'.format(number_of_full_subplots,remainder)

This creates and saves the drawings in a file in a properly formatted way, no matter what I do, the code seems to bypass the line fig.suptitle, and therefore I can not give my figure a heading. Apologies, if it seems that a lot of things are happening in this function, I did not explain, but does anyone explain why this code refuses to give the names of my numbers?

+4
source share
1 answer

, suptitle , , suptitle . savefig . , png - , 16 .

. , , ion ioff. , , , , , (, , )

import matplotlib.pyplot as plt
test_y=range(10)
test_x=[8,13,59,8,81,2,5,6,2,3]

def subplotsave_test():
    for i in range(5):
        fig = plt.figure(i)
        txt = fig.suptitle('Page '+str(i)+' of '+str(5),fontsize='20')
        for j in range(16):
            plt.subplot(4,4,j+1)
            plt.plot(test_y,test_x)          
        plt.savefig(str(i)+'.png',bbox_inches='tight',orientation='landscape')

if __name__ == '__main__':                
    subplotsave_test()

, , - plt.show(), , , , beforehanad, , plt.savefig()

def boxplot_data(self,parameters_file,figure_title):
    data = pandas.read_csv(parameters_file)
    header = data.keys()
    number_of_full_subplots = len(header)/16
    remainder = len(header)-(16*number_of_full_subplots)
    for i in range(number_of_full_subplots+1)
        fig =plt.figure(i)
        fig.suptitle(figure_title+' (n='+str(len(data[header[0]]))+') '+'Page '+str(i)+' of '+str(number_of_full_subplots),fontsize='20')
        for j in range(16):
            plt.subplot(4,4,j+1)
            if 16*i + j < len(header):
                plt.boxplot(data[header[16*i+j]])
                plt.xlabel('')    
                #You might want the showMaximized() call here - does nothing
                #on my machine but YMMV
            else:
                print '{} full figures were created and 1 partially filled \
                figure containing {} subplots'.format(number_of_full_subplots,remainder)
                break                
        plt.savefig(str(i)+'.png',bbox_inches='tight',orientation='landscape')
        plt.close(fig)                    
+3

Source: https://habr.com/ru/post/1598529/


All Articles