Python plotly legendgrouptitle_text 不作为 go.Scatter 参数

标签 python plotly legend title

我正在尝试使用 legendgrouptitle_text 在 python go.Scatter 上设置 legendgroup 标题,如 plotly doc 中所述:

但是 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/

相关文章:

python - 如何使用 scapy 计算捕获的数据包大小

python - django-sentry 的日志记录有哪些轻量级替代品?

r - 如何在 ggplot 中为 map 中的多个图层自定义图例?

python - 如何将传说保留在情节中?

r - 底部图例,两行包裹在 r 中的 ggplot2 中

Python 参数和函数

python - 当字符串等价于旋转时

r - R Shiny 的中心 plotly 图

javascript - 在 plotly.js 中手动设置 x 和 y 轴

r - R 中的 3d 曲面图与 plotly