I am writing a code that displays a plotly graph in a django template. The source of data should come from a pandas dataframe.
I have tried the one shared from this page: Embedding a Plotly chart in a Django template
and modified it as follows:
def plotly_scatter(df, _x):
x = df.iloc[:, 1:2]
y = df.iloc[:, 3:4]
trace1 = go.Scatter(x=x, y=y, marker={'color': 'red', 'symbol': 104, 'size': 10},
mode="lines", name='1st Trace')
data=go.Data([trace1])
layout=go.Layout(title="Meine Daten", xaxis={'title':'x1'}, yaxis={'title':'x2'})
figure=go.Figure(data=data,layout=layout)
div = opy.plot(figure, auto_open=False, output_type='div')
return div
Have this function called from a view with the following line
try:
df = pd.read_csv(project.base_file)
context['graph'] = plotly_scatter(df, 1)
except: pass
and tried his template:
{% if graph %}
<div style="width:600;height:500">
{{ graph|safe }}
</div>
{% endif %}
The graph plot is displayed but no line is displayed. Here is my output:
Here is the original output: