Unfortunately, it seems that rendering in a Flask app is not getting the modebar correct either. This must be somewhat working because I can draw a freeform line in black on the 2d plot… but the buttons for the controls are not in the modebar. It works perfectly in Jupyter.
x_max = df[‘X’].max()
z_max = 35 # Given as per your description
fig = px.scatter(df, x='X', y='Z', color='Label',
color_discrete_map={
"Ground" : "rgba(111,78,55,1)",
"Vegetation" : "rgba(67,102,29,1)"
})
fig.update_traces(marker=dict(size=1.25))
fig.update_layout(
legend=dict(
title_font_size=16, # Adjusts the legend title font size
font=dict(
size=14, # Adjusts the legend text font size
),
),
xaxis=dict(
title='Slice Length (meters)',
showticklabels=True,
range=[0,x_max] # Setting the x-axis range
),
yaxis=dict(
title='Height (meters)',
showticklabels=True,
scaleanchor='x',
scaleratio=1,
constrain='domain',
range=[0,z_max] # Adjusting the y-axis range
),
title_text=f'<b>Flattened LiDAR Slice Number: {slicenum}</b>',
dragmode='drawopenpath',
newshape_line_color='black',
modebar_add=['drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape']
)
graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
return render_template("plot.html", graphJSON=graphJSON).
In my html template I am including plotly
And I am using Plotly.newPlot
<script type="text/javascript">
var graphs = {{ graphJSON | safe }};
Plotly.newPlot('plot', graphs);
Developer Tools in the browser shows that the configuration is there:
“modebar”: {
“add”: [“drawline”, “drawopenpath”, “drawclosedpath”, “drawcircle”, “drawrect”, “eraseshape”]
},