我在这个主题上搜索了很多,但我不是一个Web开发人员,所以我知道我错过了一些概念。matplotlib的'webagg'后端可以与我的django网站一起工作吗?
当我在本地运行matplotlib并指定'webagg'后端时,运行plt.show()将启动一个轻量级web服务器,并通过完整的交互功能在我的浏览器中打开该图。
import matplotlib as mpl
mpl.use('webagg')
from matplotlib import pyplot as plt
import numpy as np
f,ax = plt.subplots(1)
ydata = np.random.randint(0,100,100)
xdata = np.linspace(1,100,100)
ax.plot(xdata,ydata,picker=5)
ax.set_title('Click the line to change the color')
def onpick(event):
event.artist.set_color('red')
f.canvas.draw_idle()
f.canvas.mpl_connect('pick_event', onpick)
plt.show()
我的问题是:是否有可能使用webagg后端与我的Django的网站,成为整齐的互动matplotlib数字用户?换句话说,我可以在我的django网站的某个地方使用上面的代码,这样图表就会嵌入网页中吗?我知道的工具,如mpld3,这是非常酷的,但不完全重新创建matplotlib中的部件/选择器功能)。