1

I am very new to python. I just want to know Is there any way to insert matplotlib plot on a web page using flask, without converting to static JPG or png?

This is my code:

from flask import Flask
app = Flask(__name__)
import matplotlib.pyplot as plt

@app.route("/")
def hello():

    x = [2, 4, 6]
    y = [1, 3, 5]
    plt.plot(x, y)
    plt.show()

if __name__ == "__main__":
    app.run()

This is what I expect as an output: Page

ElisaFo
  • 130
  • 13

1 Answers1

2

This question has been asked before.

While that answer will do what you want, I can't help but to tell you I think you are using the wrong tool. I suggest looking into Plotly's Dash or Bokeh as those packages are actually meant for rendering data visualizations in a web browser with Python.

pistolpete
  • 968
  • 10
  • 20