绘制两个重叠的漏斗:代码不起作用
Plotly two overlapping funnels: the code isn't working
我想可视化两个重叠的漏斗:蓝色(较宽的漏斗)和红色。我想要蓝色
一个有图例,数字,轴不可见。所以我尝试了这段代码(不起作用):
from plotly import graph_objects as go
from plotly.subplots import make_subplots
trace=go.Funnel(
name = 'all',
y = ["all leads", "not junks", "warms", "hots","deals"],
x = [317379,304725,11476,3194,2163],
textposition=None,
marker={'xaxis': {'range': [0.2, 1],
'showgrid': False,
'zeroline': False,
'visible': False}})
trace1=go.Funnel(
name = 'web',
y = ["all leads", "not junks", "warms", "hots","deals"],
x = [281316,269490,10252,2508,1602],
textposition='outside',
marker={"color": '#dc143c',"colorscale": 'Hot',"colorbar": {"bgcolor": None}})
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(trace)
fig.add_trace(trace1,secondary_y=True)
fig.show()
出现错误:错误 属性 路径
问题在于:
marker={'xaxis': {'range': [0.2, 1],
'showgrid': False,
'zeroline': False,
'visible': False}})
我不知道如何修复,但我需要它来使蓝色的图例、数字和轴不可见。没有这个代码就可以工作,但返回这个结果:
这不是我所期望的,因为它不清楚
如果我正确理解了您要实现的目标,那么只需对您的代码进行一些编辑:
from plotly import graph_objects as go
from plotly.subplots import make_subplots
trace=go.Funnel(
name = 'all',
y = ["all leads", "not junks", "warms", "hots","deals"],
x = [317379,304725,11476,3194,2163],
textposition=None,
showlegend=False,
marker={"color": 'blue'}
)
trace1=go.Funnel(
name = 'web',
y = ["all leads", "not junks", "warms", "hots","deals"],
x = [281316,269490,10252,2508,1602],
textposition='outside',
marker={"color": '#dc143c',"colorscale": 'Hot',"colorbar": {"bgcolor": None}})
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(trace)
fig.add_trace(trace1, secondary_y=True)
fig.layout.yaxis.update(showticklabels=False)
fig.layout.xaxis.update({'visible': True})
fig.for_each_trace(
lambda trace: trace.update(ids=[]) if trace.name == "all" else (),
)
fig.show()
具有 showlegend=False
的 blue/wider 漏斗图的图例已删除。使用 marker=
参数为该图表设置蓝色。使用 fig.layout.yaxis.update(showticklabels=False)
删除了该图的 y-axis。 (您可以使用 fig.layout.yaxis2.update(...)
删除其他 y-axis 的标签。)并且使用 fig.for_each_trace(...)
.
关闭该图的数字
X-axis 也通过 fig.layout.xaxis.update({'visible': True})
变为可见。
我想可视化两个重叠的漏斗:蓝色(较宽的漏斗)和红色。我想要蓝色 一个有图例,数字,轴不可见。所以我尝试了这段代码(不起作用):
from plotly import graph_objects as go
from plotly.subplots import make_subplots
trace=go.Funnel(
name = 'all',
y = ["all leads", "not junks", "warms", "hots","deals"],
x = [317379,304725,11476,3194,2163],
textposition=None,
marker={'xaxis': {'range': [0.2, 1],
'showgrid': False,
'zeroline': False,
'visible': False}})
trace1=go.Funnel(
name = 'web',
y = ["all leads", "not junks", "warms", "hots","deals"],
x = [281316,269490,10252,2508,1602],
textposition='outside',
marker={"color": '#dc143c',"colorscale": 'Hot',"colorbar": {"bgcolor": None}})
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(trace)
fig.add_trace(trace1,secondary_y=True)
fig.show()
出现错误:错误 属性 路径
问题在于:
marker={'xaxis': {'range': [0.2, 1],
'showgrid': False,
'zeroline': False,
'visible': False}})
我不知道如何修复,但我需要它来使蓝色的图例、数字和轴不可见。没有这个代码就可以工作,但返回这个结果:
如果我正确理解了您要实现的目标,那么只需对您的代码进行一些编辑:
from plotly import graph_objects as go
from plotly.subplots import make_subplots
trace=go.Funnel(
name = 'all',
y = ["all leads", "not junks", "warms", "hots","deals"],
x = [317379,304725,11476,3194,2163],
textposition=None,
showlegend=False,
marker={"color": 'blue'}
)
trace1=go.Funnel(
name = 'web',
y = ["all leads", "not junks", "warms", "hots","deals"],
x = [281316,269490,10252,2508,1602],
textposition='outside',
marker={"color": '#dc143c',"colorscale": 'Hot',"colorbar": {"bgcolor": None}})
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(trace)
fig.add_trace(trace1, secondary_y=True)
fig.layout.yaxis.update(showticklabels=False)
fig.layout.xaxis.update({'visible': True})
fig.for_each_trace(
lambda trace: trace.update(ids=[]) if trace.name == "all" else (),
)
fig.show()
具有 showlegend=False
的 blue/wider 漏斗图的图例已删除。使用 marker=
参数为该图表设置蓝色。使用 fig.layout.yaxis.update(showticklabels=False)
删除了该图的 y-axis。 (您可以使用 fig.layout.yaxis2.update(...)
删除其他 y-axis 的标签。)并且使用 fig.for_each_trace(...)
.
X-axis 也通过 fig.layout.xaxis.update({'visible': True})
变为可见。