为什么我的阴谋人物无法在Django模板中正确显示?

时间:2020-04-22 16:01:01

标签: html django django-views django-templates plotly-python

我有一个基本的python模块,我正在使用该模块输出将可重复绘制的图直接嵌入到我的Django模板中所需的div。我只想在我的网站上显示一个基本情节,以向与我一起开发的人证明概念。该图将呈现,但是如果我的光标经过数据点并在屏幕上显示坐标,则只能看到视觉反馈。否则,直线,点,轴和所有其他渲染的组件将不可见。我正在运行的代码如下。

Plotter.py

import plotly.graph_objects as go 
from plotly.offline import plot
import pandas as pd

def get_plot_div():
   x = [0,1,2,3,4,5]
   y = [6,5,4,3,4,5]
   zipped_list = list(zip(x,y))
   df = pd.DataFrame(zipped_list,columns = ['x1','x2'])

   fig = go.Figure()
   fig.add_trace(go.Scatter(
        x = df['x1'],
        y = df['x2'],
        mode = 'lines'))
   fig.update_layout(height=600, width=800, title_text="Simple Plot")
   plot_div = plot(fig, output_type = 'div',auto_open = False)
   return plot_div


Views.py

from . import Plotter.py as plotter 
from django.shortcuts import render


def Profile(request):
   plt_div_returned = plotter.get_plot_div()
   context = {'fig':plt_div_returned}
   return render(request,'django_proj/profile.html',{'context':context})

然后在我拥有的profile.html模板中

<h1> Test Plot </h1>
{% if context.fig %}
   {{%context.fig | safe%}}
{% endif %}

这将在我的模板中呈现该图,但是同样,只有将光标移到一个数据点上时,我才能看到任何内容。否则,看不到任何线或标签。但是,Redner很好。有人遇到过这个问题吗?我的css是否有可能覆盖绘图,并使所有内容与背景颜色相同?

0 个答案:

没有答案