basefunctions/plot_preprocessor.py
def plotsplitter(self, element_name, plottype):
        '''split large data frames an create subplots (month-data basis stays constant)'''

        if plottype == 'monthplot':
            plottinglist = self.plotinfo_month[element_name].copy()

        elif plottype == 'costplot':
            plottinglist = self.plotinfo_costs[element_name].copy()

        elif plottype == 'boxplot':
            plottinglist = self.plotinfo_boxplot[element_name].copy()

        elif plottype == 'vioplot':
            plottinglist = self.plotinfo_vioplot[element_name].copy()


        else:
            pass


        #split dataframes if necessary (necessary if more than 18 categories)
        for plotinfo in plottinglist:

            data_old, title_old, path_old = plotinfo

            if plottype in ('vioplot', 'boxplot'):
                #split box and violinplot every 22 categories
                box_cat_nums = data_old['cat'].unique()

                if len(box_cat_nums) > 22:
                    if len(box_cat_nums) > 66:
                        var3 = 4
                    elif len(box_cat_nums) > 44:
                        var3 = 3
                    else:
                        var3 = 2

                    plotslicing = True
                    #do first data slice
                    box_slicejump = 21 #21 as 0 ist counted as index,  as well
                    box_index_new = data_old[data_old['cat'] == box_cat_nums[box_slicejump]].index[-1]
                    slice_var = [0, box_index_new+1] #adjustments for boxplot slicing #+1 for upper slice_var as the final line of the last category has to be included (range [x:y) goes up to y but not including y])
                else:#if dataframe has less then 22 cats,  do no slicing
                    plotslicing = False

            #slices for cost and monthplots
            else:
                #split month and cost data every 18 entries
                if len(data_old) > 18:#0-17=18 (setting >18 (+1) prevents that a single entry dataframe is created)
                    if len(data_old) > 54:
                        var3 = 4
                    elif len(data_old) > 36:
                        var3 = 3
                    else:
                        var3 = 2
                    slice_var = [0, 18]
                    plotslicing = True

                else:#if cost or monthplot has less than 18 entries,  do no slicing
                    plotslicing = False


            name_var = "I"#enumerator für plots
            sublist = []

            #start plot sclicing
            if plotslicing:

                for subplot in range(0, var3):
                    #do slicing and renaming
                    new_data = data_old[slice_var[0]:slice_var[1]]
                    new_title = title_old+LANGDICT_PLOTPROC['boxsplit_partname'][0]+name_var
                    new_path = path_old[:-4]+"_"+name_var+".png"

                    #add subplot to plotting list
                    sublist.append((new_data, new_title, new_path))

                    if plottype in('vioplot', 'boxplot'):
                        #adjust slicer for boxplots (every 22 categories a new plot)

                        if subplot+2 < var3:
                            box_index_old = data_old[data_old['cat'] == box_cat_nums[box_slicejump]].index[-1]+1 #row number of last category + 1 row
                            box_slicejump += 22
                            box_index_new = data_old[data_old['cat'] == box_cat_nums[box_slicejump]].index[-1]

                        else:
                            box_index_old = data_old[data_old['cat'] == box_cat_nums[box_slicejump]].index[-1]+1 #row number of last category + 1 row
                            box_index_new = data_old.index[-1]

                        slice_var = [box_index_old, box_index_new+1] #+1 for upper slice_var as the final line of the last category has to be included (range [x:y) goes up to y but not including y])
                    else:
                        #adjust slicer for month&costplot (every 18 entries a new plot)
                        slice_var = [subplot+18 for subplot in slice_var]

                    #adjust name enumerator
                    if subplot == 2:
                        name_var = 'IV'
                    elif subplot == 3:
                        name_var = 'V'
                    else:
                        name_var = name_var+"I"

            else:
                #add plot without slicing to plotting list (basically equal to old list)
                sublist.append(plotinfo)
        # #plot data
            for subindex in range(len(sublist)):
                if subindex == 0:
                    axadjust = ("getval", (0, 0))
                else:
                    axadjust = ("setval", axvalue)

                #choose plotter
                if plottype == 'monthplot':
                    axvalue = plotters.monthplotter(sublist[subindex], axadjust, self.month_data[element_name])

                elif plottype == 'costplot':
                    axvalue = plotters.costplotter(sublist[subindex], axadjust, self.month_data[element_name])

                elif plottype == 'boxplot':
                    axvalue = plotters.boxplotter(sublist[subindex], axadjust, self.month_data[element_name])

                elif plottype == 'vioplot':
                    axvalue = plotters.violinplotter(sublist[subindex], axadjust, self.month_data[element_name])
split large data frames an create subplots (month-data basis stays constant)
split large data frames an create subplots (month-data basis stays constant)
split large data frames an create subplots ( month - data basis stays constant )
def plotsplitter(self, element_name, plottype):
        if plottype == 'monthplot':
            plottinglist = self.plotinfo_month[element_name].copy()
        elif plottype == 'costplot':
            plottinglist = self.plotinfo_costs[element_name].copy()
        elif plottype == 'boxplot':
            plottinglist = self.plotinfo_boxplot[element_name].copy()
        elif plottype == 'vioplot':
            plottinglist = self.plotinfo_vioplot[element_name].copy()
        else:
            pass
        for plotinfo in plottinglist:
            data_old, title_old, path_old = plotinfo
            if plottype in ('vioplot', 'boxplot'):
                box_cat_nums = data_old['cat'].unique()
                if len(box_cat_nums) > 22:
                    if len(box_cat_nums) > 66:
                        var3 = 4
                    elif len(box_cat_nums) > 44:
                        var3 = 3
                    else:
                        var3 = 2
                    plotslicing = True
                    box_slicejump = 21 
                    box_index_new = data_old[data_old['cat'] == box_cat_nums[box_slicejump]].index[-1]
                    slice_var = [0, box_index_new+1] 
                else:
                    plotslicing = False
            else:
                if len(data_old) > 18:
                    if len(data_old) > 54:
                        var3 = 4
                    elif len(data_old) > 36:
                        var3 = 3
                    else:
                        var3 = 2
                    slice_var = [0, 18]
                    plotslicing = True
                else:
                    plotslicing = False
            name_var = "I"
            sublist = []
            if plotslicing:
                for subplot in range(0, var3):
                    new_data = data_old[slice_var[0]:slice_var[1]]
                    new_title = title_old+LANGDICT_PLOTPROC['boxsplit_partname'][0]+name_var
                    new_path = path_old[:-4]+"_"+name_var+".png"
                    sublist.append((new_data, new_title, new_path))
                    if plottype in('vioplot', 'boxplot'):
                        if subplot+2 < var3:
                            box_index_old = data_old[data_old['cat'] == box_cat_nums[box_slicejump]].index[-1]+1 
                            box_slicejump += 22
                            box_index_new = data_old[data_old['cat'] == box_cat_nums[box_slicejump]].index[-1]
                        else:
                            box_index_old = data_old[data_old['cat'] == box_cat_nums[box_slicejump]].index[-1]+1 
                            box_index_new = data_old.index[-1]
                        slice_var = [box_index_old, box_index_new+1] 
                    else:
                        slice_var = [subplot+18 for subplot in slice_var]
                    if subplot == 2:
                        name_var = 'IV'
                    elif subplot == 3:
                        name_var = 'V'
                    else:
                        name_var = name_var+"I"
            else:
                sublist.append(plotinfo)
            for subindex in range(len(sublist)):
                if subindex == 0:
                    axadjust = ("getval", (0, 0))
                else:
                    axadjust = ("setval", axvalue)
                if plottype == 'monthplot':
                    axvalue = plotters.monthplotter(sublist[subindex], axadjust, self.month_data[element_name])
                elif plottype == 'costplot':
                    axvalue = plotters.costplotter(sublist[subindex], axadjust, self.month_data[element_name])
                elif plottype == 'boxplot':
                    axvalue = plotters.boxplotter(sublist[subindex], axadjust, self.month_data[element_name])
                elif plottype == 'vioplot':
                    axvalue = plotters.violinplotter(sublist[subindex], axadjust, self.month_data[element_name])
def plotsplitter ( self , element_name , plottype ) : if plottype == 'monthplot' : plottinglist = self . plotinfo_month [ element_name ] . copy ( ) elif plottype == 'costplot' : plottinglist = self . plotinfo_costs [ element_name ] . copy ( ) elif plottype == 'boxplot' : plottinglist = self . plotinfo_boxplot [ element_name ] . copy ( ) elif plottype == 'vioplot' : plottinglist = self . plotinfo_vioplot [ element_name ] . copy ( ) else : pass for plotinfo in plottinglist : data_old , title_old , path_old = plotinfo if plottype in ( 'vioplot' , 'boxplot' ) : box_cat_nums = data_old [ 'cat' ] . unique ( ) if len ( box_cat_nums ) > 22 : if len ( box_cat_nums ) > 66 : var3 = 4 elif len ( box_cat_nums ) > 44 : var3 = 3 else : var3 = 2 plotslicing = True box_slicejump = 21 box_index_new = data_old [ data_old [ 'cat' ] == box_cat_nums [ box_slicejump ] ] . index [ - 1 ] slice_var = [ 0 , box_index_new + 1 ] else : plotslicing = False else : if len ( data_old ) > 18 : if len ( data_old ) > 54 : var3 = 4 elif len ( data_old ) > 36 : var3 = 3 else : var3 = 2 slice_var = [ 0 , 18 ] plotslicing = True else : plotslicing = False name_var = "I" sublist = [ ] if plotslicing : for subplot in range ( 0 , var3 ) : new_data = data_old [ slice_var [ 0 ] : slice_var [ 1 ] ] new_title = title_old + LANGDICT_PLOTPROC [ 'boxsplit_partname' ] [ 0 ] + name_var new_path = path_old [ : - 4 ] + "_" + name_var + ".png" sublist . append ( ( new_data , new_title , new_path ) ) if plottype in ( 'vioplot' , 'boxplot' ) : if subplot + 2 < var3 : box_index_old = data_old [ data_old [ 'cat' ] == box_cat_nums [ box_slicejump ] ] . index [ - 1 ] + 1 box_slicejump += 22 box_index_new = data_old [ data_old [ 'cat' ] == box_cat_nums [ box_slicejump ] ] . index [ - 1 ] else : box_index_old = data_old [ data_old [ 'cat' ] == box_cat_nums [ box_slicejump ] ] . index [ - 1 ] + 1 box_index_new = data_old . index [ - 1 ] slice_var = [ box_index_old , box_index_new + 1 ] else : slice_var = [ subplot + 18 for subplot in slice_var ] if subplot == 2 : name_var = 'IV' elif subplot == 3 : name_var = 'V' else : name_var = name_var + "I" else : sublist . append ( plotinfo ) for subindex in range ( len ( sublist ) ) : if subindex == 0 : axadjust = ( "getval" , ( 0 , 0 ) ) else : axadjust = ( "setval" , axvalue ) if plottype == 'monthplot' : axvalue = plotters . monthplotter ( sublist [ subindex ] , axadjust , self . month_data [ element_name ] ) elif plottype == 'costplot' : axvalue = plotters . costplotter ( sublist [ subindex ] , axadjust , self . month_data [ element_name ] ) elif plottype == 'boxplot' : axvalue = plotters . boxplotter ( sublist [ subindex ] , axadjust , self . month_data [ element_name ] ) elif plottype == 'vioplot' : axvalue = plotters . violinplotter ( sublist [ subindex ] , axadjust , self . month_data [ element_name ] )
split large data frames an create subplots (month-data basis stays constant)
split large data frames an create subplots ( month - data basis stays constant )
'''split large data frames an create subplots (month-data basis stays constant)''' #split dataframes if necessary (necessary if more than 18 categories) #split box and violinplot every 22 categories #do first data slice #21 as 0 ist counted as index,  as well #adjustments for boxplot slicing #+1 for upper slice_var as the final line of the last category has to be included (range [x:y) goes up to y but not including y]) #if dataframe has less then 22 cats,  do no slicing #slices for cost and monthplots #split month and cost data every 18 entries #0-17=18 (setting >18 (+1) prevents that a single entry dataframe is created) #if cost or monthplot has less than 18 entries,  do no slicing #enumerator für plots #start plot sclicing #do slicing and renaming #add subplot to plotting list #adjust slicer for boxplots (every 22 categories a new plot) #row number of last category + 1 row #row number of last category + 1 row #+1 for upper slice_var as the final line of the last category has to be included (range [x:y) goes up to y but not including y]) #adjust slicer for month&costplot (every 18 entries a new plot) #adjust name enumerator #add plot without slicing to plotting list (basically equal to old list) # #plot data #choose plotter
self
element_name
plottype