Closed
Description
I am using plotly to generate a 3d scatter graph to embed in a django website. I am having a couple of issues - they look buggy but I am unfamiliar with this tool so its also possible I'm just not using correctly.
The code
Here's the relevant section of my code. The code simply iterates over a pandas.groupby
object to plot experimental factors a different colour.
for label, df in pca_data.groupby(by=colour_by):
trace = go.Scatter3d(
x=numpy.array(df['pc1']),
y=numpy.array(df['pc2']),
z=numpy.array(df['pc3']),
mode='markers',
marker={
'color': col.__next__(),
'opacity': 0.75
},
name=label if isinstance(label, (str, int, float)) else reduce(lambda x, y: "{}_{}".format(x, y), label)
)
traces.append(trace)
layout = go.Layout(
margin=dict(l=0, r=0, b=0, t=0),
height=600,
xaxis={
'title': 'PC1 ({}% variance explained)'.format(explained_var.iloc[0]),
},
yaxis={'title': 'PC2 ({}% variance explained'.format(explained_var.iloc[1])},
legend={
'font': {
'size': 20
}
}
# zaxis={'title': 'PC3 ({}% variance explained'.format(explained_var.iloc[2])}
)
fig = go.Figure(data=traces, layout=layout)
p = pyo.plot(
figure_or_data=fig,
output_type='div',
auto_open=False,
config={'displayModeBar': False}
)
Problem 1: The Mode Bar
Using the `pyo.plot` with `output_type='file'` works as expected but when set to `div` as I need for embedding into a django site, the mode buttons are massive and all over the place. My only solution so far has been to suppress the mode bar. The other solution that kind of worked was to use css to set the height/width of `modebar-group` css classes - however, here we get some overlapping buttons. Heres a screen shot without the mode bar suppressed.Problem 2: Axis labels
The (docs)[https://plot.ly/python/figure-labels/] suggest that axis labels should be given as in the above code snippet, however my axis labels remain unchanged. In addition, the zaxis argument into `go.Layout` raises an error, complaining that `zaxis` is not an argument for Layout, though docs seem to indicate this is the way its done.Problem 3: error in chrome
When I look in Chrome developer tools, it seems that the code that is auto-generated by plotly contains an error. I'm not sure to what extent this error may be causing the others.Here's the error
pca:73 Uncaught (in promise) Error: addFrames failure: frameList must be an Array of frame definitions[object Object]
at Object.r.addFrames (pca:73)
at pca:79
The full project can be obtained from (here)[https://github.com/CiaranWelsh/data_viz_with_django/tree/develop] on the develop branch. Run python manage.py runserver
, navigate to the PCA
page and press submit to reproduce the problems.
I am running the Python version 3.6.5 with the latest install of plotly and django.
Metadata
Metadata
Assignees
Labels
No labels