visualize.py 文件源码

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

项目:arXivTimesIndicator 作者: chakki-works 项目源码 文件源码
def save_graph_with_icon(x, y, images, file_name):
    plt.clf()
    sns.set_style("whitegrid")
    ax = sns.barplot(x=x, y=y, ci=None)

    # erase ticks
    ax.get_xaxis().set_ticklabels([], fontsize=45)  # expand label size by fontsize parameter
    TICK_POS = -0.25
    SIZE_IN_TICK = 1

    scale = ax.transData.transform((1, 1)) - ax.transData.transform((0, 0))
    x_scale = scale[0] / scale[1]

    for i, _x in enumerate(x):
        label_x = _x  # adjustment is not needed in saved file
        left = label_x - (SIZE_IN_TICK / x_scale / 2)
        down = TICK_POS - SIZE_IN_TICK
        right = label_x + (SIZE_IN_TICK / x_scale / 2)
        top = TICK_POS
        leftDown = ax.transData.transform((left, down))
        rightUpper = ax.transData.transform((right, top))
        bbox_image = BboxImage(Bbox([leftDown, rightUpper]),
                               norm=None,
                               origin=None,
                               clip_on=False
                               )
        bbox_image.set_data(images[i])
        ax.add_artist(bbox_image)
    plt.savefig(file_name)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号