Yasser Sami
Yasser Sami

Reputation: 121

Python plotly legendgrouptitle_text is not working as go.Scatter argument

I'm trying to use legendgrouptitle_text to set legendgroup title on python go.Scatter as mentionned in plotly doc:

But go.Scatter refuses it as argument and suggest other inaproriate argument :

    Did you mean "legendgroup"?

    Bad property path:

    legendgrouptitle_text
    ^^^^^^^^^^^^^^^^

Here's a snippet code of how I try to use it

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) + ']',
    )
)

Many thanks in advance !

Upvotes: 3

Views: 2684

Answers (1)

Rob Raymond
Rob Raymond

Reputation: 31226

For me it was a straight versions issue. This is a new feature in plotly 5.1.0. Failed when using 5.0.0 (also remember to restart your kernel if using Jupyter after upgrading)

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) + "]",
))

Upvotes: 2

Related Questions