Plotly - Plotting k-means clusters on plotly won't work

Viewed 1538

I have a dataframe of 900k+ rows and 28 columns. I'm using this code snippet that i found in at this example at the plotly official website:

import plotly.plotly as py
import pandas as pd

scatter = dict(
    mode = "markers",
    name = "y",
    type = "scatter3d",    
    x = col1, y = col2, z = col3,
    marker = dict( size=2, color="rgb(23, 190, 207)" )
)
clusters = dict(
    alphahull = 7,
    name = "y",
    opacity = 0.1,
    type = "mesh3d",    
    x = col1, y = col2, z = col3
)
layout = dict(
    title = '3d point clustering',
    scene = dict(
        xaxis = dict( zeroline=False ),
        yaxis = dict( zeroline=False ),
        zaxis = dict( zeroline=False ),
    )
)
fig = dict( data=[scatter, clusters], layout=layout )
# Use py.iplot() for IPython notebook
py.plot(fig, filename='3d point clustering')

my df has already been loaded. Note that col2 has 'object' dtype.

I'm running this in jupyter notebook. When i run this code, everything seems to go right, but i have this warning showing up:

UserWarning:

Woah there! Look at all those points! Due to browser limitations, the Plotly SVG drawing functions have a hard time graphing more than 500k data points for line charts, or 40k points for other types of charts. Here are some suggestions:
(1) Use the `plotly.graph_objs.Scattergl` trace object to generate a WebGl graph.
(2) Trying using the image API to return an image instead of a graph URL
(3) Use matplotlib
(4) See if you can create your visualization with fewer data points

If the visualization you're using aggregates points (e.g., box plot, histogram, etc.) you can disregard this warning.

This warning comes up like 7 times in a row. It looks like there must some limitation to make this plots in a web browser based UI like jupyter notebooks.

I tried to import the module 'plotly.graph_objs.Scattergl' but it says there is no such module in pyplot.

I just don't know how to workaround this limitation. In case this cannot be done, how could i make a similar plot using matplotlib? Any help will be much appreciated.

Thank you very much

1 Answers

Maybe you wrong call Scattergl... Check here.

I think this is what you looking for (example is taken from the documentation):

import plotly.graph_objs as go
trace = go.Scattergl(...)

Hope it helps

Related