plot.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:powerplantmatching 作者: FRESNA 项目源码 文件源码
def comparison_1dim(by='Country', include_WEPP=True, include_VRE=False,
                    year=2015, how='hbar', figsize=(7,5)):
    """
    Plots a horizontal bar chart with capacity on x-axis, ``by`` on y-axis.

    Parameters
    ----------
    by : string, defines how to group data
        Allowed values: 'Country' or 'Fueltype'

    """
    red_w_wepp, red_wo_wepp, wepp, statistics = gather_comparison_data(include_WEPP=include_WEPP,
                                                                       include_VRE=include_VRE,
                                                                       year=year)
    if include_WEPP:
        stats = lookup([red_w_wepp, red_wo_wepp, wepp, statistics],
                       keys=['Matched dataset w/ WEPP', 'Matched dataset w/o WEPP',
                             'WEPP only', 'Statistics OPSD'], by=by)/1000
    else:
        stats = lookup([red_wo_wepp, statistics],
                       keys=['Matched dataset w/o WEPP', 'Statistics OPSD'],
                       by=by)/1000

    if how == 'hbar':
        with sns.axes_style('darkgrid'):
            font={'size'   : 24}
            plt.rc('font', **font)
            fig, ax = plt.subplots(figsize=figsize)
            stats.plot.barh(ax=ax, stacked=False, colormap='jet')
            ax.set_xlabel('Installed Capacity [GW]')
            ax.yaxis.label.set_visible(False)
            #ax.set_facecolor('#d9d9d9')                  # gray background
            ax.set_axisbelow(True)                       # puts the grid behind the bars
            ax.grid(color='white', linestyle='dotted')   # adds white dotted grid
            ax.legend(loc='best')
            ax.invert_yaxis()
        return fig, ax
    if how == 'scatter':
        stats.loc[:, by] = stats.index.astype(str) #Needed for seaborne
        if len(stats.columns)-1 >= 3:
            g = sns.pairplot(stats, diag_kind='kde', hue=by, palette='Set2',
                             size=figsize[1], aspect=figsize[0]/figsize[1])
        else:
            g = sns.pairplot(stats, diag_kind='kde', hue=by, palette='Set2',
                             size=figsize[1], aspect=figsize[0]/figsize[1],
                             x_vars=stats.columns[0], y_vars=stats.columns[1])
        for i in range(0, len(g.axes)):
            for j in range(0, len(g.axes[0])):
                g.axes[i,j].set(xscale='log', yscale='log', xlim=(1,200), ylim=(1,200))
        return g.fig, g.axes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号