graph.py 文件源码

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

项目:plumeria 作者: sk89q 项目源码 文件源码
def histogram(message):
    """
    Generate a histogram from a list of numbers separated by new lines, semi-colons,
    commas, or spaces. Currently, the bin count is locked to 10.

    Example::

        /hist 20 39 19 17 28 39 29 20 11 29 32 44
        /roll 500d10 | hist

    """
    data = parse_numeric_list(message.content)

    def execute():
        with lock:
            plt.figure(1, figsize=(5, 5))
            ax = plt.axes([0.1, 0.1, 0.4, 0.4])

            plt.hist(data, bins=10)

            prop = fm.FontProperties(fname=font_path, size=11)
            for text in ax.texts:
                text.set_fontproperties(prop)

            buf = io.BytesIO()
            plt.savefig(buf, bbox_inches='tight', transparent=False, pad_inches=0.1)

            plt.clf()
        return buf

    buf = await asyncio.get_event_loop().run_in_executor(None, execute)

    return Response("", attachments=[MemoryAttachment(buf, "graph.png", "image/png")])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号