plot.py 文件源码

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

项目:psst 作者: power-system-simulation-toolbox 项目源码 文件源码
def plot_costs(case, number_of_segments=1, ax=None, legend=True):
    if ax is None:
        fig, axs = plt.subplots(1, 1, figsize=(16, 10))
        ax = axs

    color_scale = make_interpolater(0, len(case.gen_name), 0, 1)

    color = {g: plt.cm.jet(color_scale(i)) for i, g in enumerate(case.gen_name)}

    for s in calculate_segments(case, number_of_segments=number_of_segments):
        pmin, pmax = s['segment']
        x = np.linspace(pmin, pmax)
        y = x * s['slope']
        ax.plot(x, y, color=color[s['name']])

    ax = ax.twinx()
    for s in calculate_segments(case, number_of_segments=number_of_segments):
        pmin, pmax = s['segment']
        x = np.linspace(pmin, pmax)
        y = [s['slope'] for _ in x]
        ax.plot(x, y, color=color[s['name']])

    ax.set_ylim(0, 1.2*y[-1])

    if legend:
        lines = list()
        for g in case.gen_name:
            lines.append(mlines.Line2D([], [], color=color[g], label=g))
            ax.legend(handles=lines, loc='upper left')

    return ax
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号