我试图在我的django模板上绘制一个可绘制的图,但是无法这样做,得到一个空白模板。
#plotly libraries used
import plotly.graph_objects as go
import plotly.express as px
import plotly.offline as py
def home(request):
df=index(request) #returns a dataframe
#overall cases
total_df = df.groupby(['Country'])['Total Cases'].sum()
total_df = total_df.reset_index()
fig0 = px.scatter_geo(total_df,locations="Country", locationmode='country names',
color="Total Cases", size='Total Cases',hover_name="Country",
projection="orthographic",color_continuous_scale=px.colors.sequential.deep,
)
fig0 = go.Figure(data=fig0)
plot_div0 = py.plot(fig0, include_plotlyjs=False, output_type='div',config={'displayModeBar': False})
return render(request, 'test/welcome.html', {'plot_div0':plot_div0})
{{ plot_div0 | safe }}
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>