我正在尝试使用 legendgrouptitle_text
在 python go.Scatter
上设置 legendgroup 标题,如 plotly doc 中所述:
- https://plotly.com/python/legend/
- https://plotly.com/python/reference/scatterpolar/#scatterpolar-legendgrouptitle
但是 go.Scatter 拒绝将其作为论点并提出其他不恰当的论点:
Did you mean "legendgroup"?
Bad property path:
legendgrouptitle_text
^^^^^^^^^^^^^^^^
这是我尝试使用它的代码片段
traces.append(
go.Scatter(
x=X_1d,
y=y_1d,
name=', '.join(features_values),
showlegend=True,
line=dict(
color=color,
dash='solid',
width=2,
),
marker=dict(
color=color,
symbol='circle',
size=marker_size,
),
opacity=opacity,
legendgroup='fixed_features',
legendgrouptitle_text='[' + ', '.join(legend_features) + ']',
)
)
提前致谢!
最佳答案
对我来说,这是一个直接的版本问题。这是 plotly 5.1.0 中的新功能。使用 5.0.0 时失败(如果升级后使用 Jupyter,还记得重新启动内核)
import numpy as np
import plotly.graph_objects as go
X_1d = np.linspace(0,5,20)
y_1d = np.random.uniform(5,10,20)
features_values =["hello","world"]
legend_features = ["foo","bar"]
color="red"
marker_size=3
opacity=.7
go.Figure(go.Scatter(
x=X_1d,
y=y_1d,
name=", ".join(features_values),
showlegend=True,
line=dict(
color=color,
dash="solid",
width=2,
),
marker=dict(
color=color,
symbol="circle",
size=marker_size,
),
opacity=opacity,
legendgroup="fixed_features",
legendgrouptitle_text="[" + ", ".join(legend_features) + "]",
))
关于Python plotly legendgrouptitle_text 不作为 go.Scatter 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68227767/