我在這個主題上搜索了很多,但我不是一個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中的部件/選擇器功能)。