我对Flask和matplotlib有问题。我编写了一个简单的API,它从matplotlib返回一个图表。当两个用户同时发送请求时,即使我为图表创建了单独的类,图表也会相互重叠
这是我的密码:
class WykresXT:
def make(self, amp, okres):
name = random.randint(0, 1000000)
time = np.arange(0, 20, 0.1)
plot.plot(time, calc_xt(amp=float(amp), czas=time, okres_d=float(okres)))
plot.title('Wykres x(t)')
plot.xlabel('t (czas)')
plot.ylabel('x (wychylenie)')
plot.grid(True, which='both')
plot.axhline(y=0, color='k')
plot.savefig(str(name) + '.png')
plot.close()
plot.figure().clear()
return str(name) + '.png'
@app.route('/wykres_x', methods=['GET'])
def wykres_x():
args = {"amp": request.args.get('amp'), "okres": request.args.get('okres'), "faza": request.args.get('faza')}
if args["amp"] is not None and args["okres"] is not None and args["faza"] is not None:
wykres = WykresXT()
return send_file(wykres.make(args["amp"], args["faza"], args["okres"]))
else:
return "podaj: '?amp=' '&okres=' '&faza='"
还有一个重叠问题的例子:
好的,所以我能够复制你的错误,并设法在我这端修复它。在那边测试一下,看看它是否适合你
我创建这个脚本是为了一次发送多个请求,这些请求来自另一个SO帖子
当我在您的服务器运行时运行此程序时,正如所料,我得到了一些彩色的图形
然后,我将pyplot调用从隐式更改为显式,正如我在注释中提到的那样。这是你的课
它现在创建了一组数字,所有这些数字都按照您的需要分开
相关问题 更多 >
编程相关推荐