【问题标题】:Plotly - Plotting k-means clusters on plotly won't workPlotly - 在 plotly 上绘制 k-means 集群不起作用
【发布时间】:2018-10-30 21:37:50
【问题描述】:

我有一个 900k+ 行和 28 列的数据框。我正在使用我在 plotly 官方网站上的at this example 中找到的这段代码 sn-p:

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')

我的 df 已经加载。请注意,col2 具有 'object' dtype。

我在 jupyter notebook 中运行它。当我运行这段代码时,一切似乎都正常,但我出现了这个警告:

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.

此警告连续出现 7 次。看起来必须有一些限制才能在基于 Web 浏览器的 UI(如 jupyter notebooks)中制作此图。

我试图导入模块'plotly.graph_objs.Scattergl',但它说pyplot中没有这样的模块。

我只是不知道如何解决这个限制。如果无法做到这一点,我如何使用matplotlib 制作类似的情节?任何帮助将不胜感激。

非常感谢

【问题讨论】:

    标签: python python-3.x matplotlib plotly


    【解决方案1】:

    也许你打错了Scattergl...检查here

    我认为这就是您要寻找的(示例取自文档):

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

    希望对你有帮助

    【讨论】:

    • 谢谢!!这完全适合我。现在我看到了问题出在哪里,但无论如何这是一个 2d 情节,有没有一种奇特的方式来绘制这个或多或少与使用 3d 相同的方式?再次感谢
    • @miguel-2488,很高兴听到这个消息)。看scatter3d。也许这就是你想要的
    • 非常感谢!!这正是我想要的:D
    猜你喜欢
    • 2017-08-10
    • 1970-01-01
    • 2019-06-10
    • 2017-07-28
    • 2020-09-23
    • 1970-01-01
    • 2020-12-27
    • 2016-03-12
    • 1970-01-01
    相关资源
    最近更新 更多