def bar(message):
"""
Generate a bar graph. To specify the individual bar labels and values, make a
list separated by new lines, semi-colons or commas where each
list entry has a number in it (if there is more than one, the
first number is used).
To specify a graph title, don't provide a number for one of the
list items.
Example::
/bar Groups, Man O 100, rationale. 20
"""
title, labels, data = extract_data(message.content, pattern=NUMBER_PATTERN)
def execute():
width = 0.8
ind = np.arange(len(data)) - width
with lock:
plt.figure(1, figsize=(5, 5))
ax = plt.axes([0.1, 0.1, 0.4, 0.4])
plt.bar(ind, data, width, align='center')
plt.xticks(rotation=70)
ax.set_xticks(ind)
ax.set_xticklabels(labels)
if title:
plt.title(title)
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")])
评论列表
文章目录