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

Method to merge results plots #355

Open camiloramirezgo opened 1 year ago

camiloramirezgo commented 1 year ago

Create a method to combine result plots as we do in latex for the publications. This method should be part of the OnStove class and allow one to take in different axes and position them.

camiloramirezgo commented 1 year ago

This is as far as I could get, as it is difficult to combine plotnine and matplotlib figures:

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(12,9))

ax_dict = fig.subplot_mosaic(
    [
        ["bar", "map", "map"],
        ["hist", "map", "map"],
        ["ben", "map", "map"]
    ],
)

p = results.plot_split(cmap=cmap, labels=labels)
p.figure = fig
p.figure._themeable = {}
p._draw_using_figure(fig, [ax_dict['bar']])

p = results.plot_costs_benefits(labels=labels, height=1.5, width=2)
p.figure = fig
p.figure._themeable = {}
p._draw_using_figure(fig, [ax_dict['ben']])

p = results.plot_benefit_distribution(type='histogram', groupby='None', variable='wealth',
                                  cmap=cmap, labels=labels, height=1.5, width=3.5)
p.figure = fig
p.figure._themeable = {}
p._draw_using_figure(fig, [ax_dict['hist']])

results.plot('max_benefit_tech', ax=ax_dict['map'], cmap=cmap, legend_position=(0.85, 0.7),
             stats_fontsize=9, figsize=(7, 7),
             labels=labels, legend=True, legend_title='Maximum benefit technology', dpi=300,
             legend_prop={'title': {'size': 9, 'weight': 'bold'}, 'size': 9},
             rasterized=True, stats=True, stats_position=(0.85, 0.9), save_style=False)

Which outputs: Image

Something to notice is that the layout of the plotnine figures gets affected, this can be seen in the grids, the axis labels, and the legend of the figures getting messed up.

This requires more research, so we should leave this issue outside of the trieste milestone. If we really want this functionality in the future, maybe it is worth considering rewriting the plotnine figures using seaborn or pure matplotlib, this will allow for much easier merge of plots.

babakkhavari commented 1 year ago

Ok I agree, lets park this one currently