How to specify the x coordinate on a grouped bar chart on plotly?

I made a bar chart with python plotly, and I want to put a marker on a particular bar, example non-smoking females. Does anyone know how to specify this?

I took an example from the plotly documentation, if I try to put the marker it just takes the center of the main category.

import plotly.express as px
df = px.data.tips()
fig = px.histogram(df, x="sex", y="total_bill",
             color='smoker', barmode='group',
             height=400)

#trying to set the marker
fig.add_trace(
    go.Scatter(x=["Female"],
               y=[1100]
              ))
fig.show()

Hi @Montes-JMa,

I found this thread - scattermode = group Β· Issue #4913 Β· plotly/plotly.js Β· GitHub where a workaround with go.Box is posted.
Maybe this could help.

Thank you so much.

I actually solved it with a second axis. I leave the link in case someone else has this problem.

2 Likes