al rein
al rein

Reputation: 61

TypeError: line() got an unexpected keyword argument 'markers'

I'm trying to use "markers" for the line function with plotly 5.4.0

import plotly.express as px

df_temp =  df_temp[df_temp.date_str.isin(selected_dates)]
        fig = px.line(df_temp, x='trialID', y='reaction_time', color='date_str', markers=True,
                         title=f'Graph2. Intervention status: {status}')

i get the error:

TypeError: line() got an unexpected keyword argument 'markers'

i read that it's about an update but i don't think it's that. does anyone know what it could be?

Upvotes: 6

Views: 10124

Answers (2)

RvdV
RvdV

Reputation: 466

Plotly's documentation marks this as a valid parameter:

markers (boolean (default False)) – If True, markers are shown on lines.

taken from plotly.express.line documentation

For me upgrading the plotly version fixed it. You can check the plotly version with import plotly and then plotly.__version__. (You can do that for any library actually). I can't seem to find history on the API spec as to when they introduced, but from the answers above it works in 5.4, and for me it didn't work in 5.1.

Upvotes: 0

Rob Raymond
Rob Raymond

Reputation: 31226

  • you have not provided a MWE. Have simulated df_temp, selected_dates, status
  • with this it runs without issue with plotly 5.4.0
import plotly.express as px
import pandas as pd
import numpy as np

df_temp = pd.DataFrame(
    {
        "date_str": np.repeat(pd.date_range("1-jan-2021", periods=10), 10).astype(str),
        "trialID": np.tile(np.arange(10), 10),
        "reaction_time": np.random.uniform(0, 2, 100),
    }
)

selected_dates = pd.Series(df_temp["date_str"].unique()).sample(5).values
status = "my favorite status"

df_temp = df_temp[df_temp.date_str.isin(selected_dates)]
fig = px.line(
    df_temp,
    x="trialID",
    y="reaction_time",
    color="date_str",
    markers=True,
    title=f"Graph2. Intervention status: {status}",
)

fig

enter image description here

Upvotes: 0

Related Questions