首页 > 解决方案 > plotly中的漏斗图

问题描述

我正在尝试使用 plotly 创建一个漏斗图并且没有任何运气。即使是来自 plotly 的罐头示例也不适合我,有人可以帮忙吗?

from plotly import graph_objects as go

fig = go.Figure(go.Funnel(
    y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"],
    x = [39, 27.4, 20.6, 11, 2]))

fig.show()

我得到这个巨大的回溯错误:

lueError:接收值的“数据”属性接收到的类型“plotly.graph_objs.Funnel”的无效值:Funnel({“x”:[39、27.4、20.6、11、2],“y”:[网站访问, 下载, 潜在客户, 要求的价格, 已发送发票] })

The 'data' property is a tuple of trace instances
that may be specified as:
  - A list or tuple of trace instances
    (e.g. [Scatter(...), Bar(...)])
  - A list or tuple of dicts of string/value properties where:
    - The 'type' property specifies the trace type
        One of: ['area', 'bar', 'barpolar', 'box',
                 'candlestick', 'carpet', 'choropleth', 'cone',
                 'contour', 'contourcarpet', 'funnel',
                 'funnelarea', 'heatmap', 'heatmapgl',
                 'histogram', 'histogram2d',
                 'histogram2dcontour', 'isosurface', 'mesh3d',
                 'ohlc', 'parcats', 'parcoords', 'pie',
                 'pointcloud', 'sankey', 'scatter',
                 'scatter3d', 'scattercarpet', 'scattergeo',
                 'scattergl', 'scattermapbox', 'scatterpolar',
                 'scatterpolargl', 'scatterternary', 'splom',
                 'streamtube', 'sunburst', 'surface', 'table',
                 'violin', 'volume', 'waterfall']

    - All remaining properties are passed to the constructor of
      the specified trace type

    (e.g. [{'type': 'scatter', ...}, {'type': 'bar, ...}])

标签: python-3.xplotly

解决方案


似乎您使用的是版本 3,在这种情况下您将需要使用go.Figure(data=[go.Funnel(...)])(基本上将您的漏斗跟踪包装在一个数组中......仅在版本 4 中是可选的)


推荐阅读