【问题标题】:Django - i want to view this plot into BrowserDjango - 我想在浏览器中查看这个图
【发布时间】:2021-07-05 03:00:56
【问题描述】:

我是 Django 新手,现在我可以传递变量,但我不知道如何渲染动态图



from datetime import datetime
from matplotlib import pyplot
from matplotlib.animation import FuncAnimation
from random import randrange

x_data, y_data = [], []

figure = pyplot.figure()
line, = pyplot.plot_date(x_data, y_data, '-')

def update(frame):
    x_data.append(datetime.now())
    y_data.append(randrange(0, 100))
    line.set_data(x_data, y_data)
    figure.gca().relim()
    figure.gca().autoscale_view()
    return line,

animation = FuncAnimation(figure, update, interval=200)

pyplot.show()

【问题讨论】:

  • 为什么要在这里使用 Django?你知道你的模型吗?

标签: python django


【解决方案1】:

通过 pyplot (python) 渲染的图形在浏览器中不会是动态的。您可以使用任何动态的 javascript 图表库并从 Django 提供数据(通过使用 REST API、Ajax 或简单请求)。

【讨论】:

    猜你喜欢
    • 2021-04-11
    • 2019-06-12
    • 2013-09-01
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多