【发布时间】:2020-05-15 05:23:56
【问题描述】:
当我使用 plot 命令时,我希望它使用 matplotlib.pyplot 对数字进行排序和绘图,但我得到了这个可憎的
https://cdn.discordapp.com/attachments/710208448326795404/710593242177208491/Picture69lmao.png
发生这种情况是因为每次我运行 plot 命令时,它都会在上一个图表上绘制,弄乱 p 轴和所有内容。我想知道你如何防止这种情况发生。这是我的代码:
import discord
import matplotlib.pyplot as plt
import os
import numpy as np
from discord.ext import commands
@bot.command()
async def plot(self, ctx, xvals, yvals):
xList = []
yList = []
for varx in xvals:
xList.append(varx)
for vary in yvals:
yList.append(vary)
xList.sort()
yList.sort()
x = np.array(xList)
y = np.array(yList)
arr = np.vstack((x, y))
plt.plot(arr[0], arr[1])
plt.title(f'{ctx.message.author}\'s Graph')
plt.savefig(fname='plot')
await ctx.send(file=discord.File('plot.png'))
os.remove('plot.png')
我对列表进行了排序,这样它就不会弄乱坐标轴,我运行如下命令:.plot "x values" "y values"
【问题讨论】:
标签: python numpy matplotlib plot discord.py-rewrite