Open-Source-Spatial-Clean-Cooking-Tool / OnStove

This repository contain the general code for the Open Source Spatial Clean Cooking Tool OnStove
MIT License
7 stars 8 forks source link

Vertical tech split plot #294

Closed camiloramirezgo closed 1 year ago

camiloramirezgo commented 1 year ago

There is need for a vertical tech split plot as now we are combining the main maps from the two perspectives and we want to show the technology share there too. A simple implementation of that can be done using the current plot_split method but removing the coord_flip and the x-axis labels:

def plot_split2(self, cmap=None, labels=None, save_as=None, height=1.5, width=2.5, x_variable='Calibrated_pop'):
    df = self.summary(total=False, pretty=False, labels=labels)

    variables = {'Calibrated_pop': 'Population (Millions)', 'Households': 'Households (Millions)'}

    tech_list = df.sort_values(x_variable)['max_benefit_tech'].tolist()
    ccolor = 'black'

    p = (ggplot(df)
         + geom_col(aes(x='max_benefit_tech', y=x_variable, fill='max_benefit_tech'))
         + geom_text(aes(y=df[x_variable], 
                         x='max_benefit_tech',
                         label=df[x_variable] / df[x_variable].sum()),
                     format_string='{:.0%}',
                     color=ccolor, 
                     size=8, 
                     ha='center', 
                     va='bottom')
         + ylim(0, df[x_variable].max() * 1.15)
         + scale_x_discrete(limits=tech_list)
         + scale_fill_manual(cmap)
         # + coord_flip()
         + theme_minimal()
         + theme(legend_position='none', axis_text_x=element_blank())
         + labs(x='Stove share', y=variables[x_variable], fill='Cooking technology')
         )
    if save_as is not None:
        file = os.path.join(self.output_directory, f'{save_as}.pdf')
        p.save(file, height=height, width=width)
    else:
        return p

Ideally, we should add an option to the current plot_split method where the user can choose the plot's orientation.