烧瓶中的 Matplotlib(谷歌 Colab)

时间:2021-07-03 05:58:25

标签: python matplotlib flask google-colaboratory

我正在尝试使用 Flask 显示我的图表,但我得到的只是一个图像占位符。代码正在运行,因为图像保存在我的 colab 文件中,并且图形是正确的,但它没有显示在 Flask 中。请帮忙。

Flask.py:

from flask import Flask, render_template
import matplotlib.pyplot as plt
from flask import *
from flask_ngrok import run_with_ngrok
from google.colab import files
import seaborn as sns
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
app = Flask(__name__)

@app.route('/plot')
def plot():
   plt.plot(real_stock_price, color = 'red', label = 'Real price')
   plt.plot(predicted_stock_price, color = 'blue', label = 'Predicted price')
   plt.title('Google price prediction')
   plt.xlabel('Time')
   plt.ylabel('Price')
   plt.legend()
   plt.savefig('plot.png')
   return render_template('plot.html', url='plot.png')
app.run()

Plot.html:

<html>
  <body>
  <img src='plot.png' alt="Chart" height="auto" width="100%">
  </body>
</html>

任何建议都会很棒!

0 个答案:

没有答案