【问题标题】:How do i integrate my matplotlib animation graph with flask web ui我如何将我的 matplotlib 动画图与烧瓶 web ui 集成
【发布时间】:2021-07-01 11:03:05
【问题描述】:

我通过在 python 中使用 matplotlib 读取电池电压和电流以及其他一些参数来绘制数据。我正在使用 Funcanimation 为情节设置动画。它实时绘图。每秒都在读取数据。我现在可以使用 matplotlib 来完成,我想使用 flask 将这个 matplotlib 添加到 web 应用程序中,它应该具有与以前相同的功能。关于我应该如何处理它的任何建议。任何帮助,将不胜感激。提前致谢。

这是我的图表如何绘制数据的视频,只是为了让您了解我在说什么。

这是视频的链接。 https://drive.google.com/file/d/1XCw__YgY0MmrsQadQ5Z0at3Uk5H5vKC-/view?usp=sharing

【问题讨论】:

    标签: python html css matplotlib flask


    【解决方案1】:

    试试这个也许它会解决你的问题

    import base64
    from io import BytesIO
    
    from flask import Flask
    from matplotlib.figure import Figure
    
    app = Flask(__name__)
    
    
    @app.route("/")
    def hello():
        # Generate the figure **without using pyplot**.
        fig = Figure()
        ax = fig.subplots()
        ax.plot([1, 2])
        # Save it to a temporary buffer.
        buf = BytesIO()
        fig.savefig(buf, format="png")
        # Embed the result in the html output.
        data = base64.b64encode(buf.getbuffer()).decode("ascii")
        return f"<img src='data:image/png;base64,{data}'/>"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-08
      • 2018-09-26
      • 2020-06-04
      • 2013-12-05
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多