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

ChemaChiles

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()

enter image description here

Rob Raymond
import plotly.express as px
import plotly.graph_objects as go
import numpy as np

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=[0.15],
        y=[1100],
        customdata=[["No", "Female"]],
        xaxis="x2",
        hovertemplate="smoker=%{customdata[0]}<br>sex=%{customdata[1]}<br>sum of total_bill=%{y}<extra></extra>",
    )
)
fig.update_layout(xaxis2={"overlaying": "x", "range": [0, 1], "showticklabels": False})

fig

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Grouped bar chart with Plotly

How to color bars in grouped plotly bar chart

How to add a Pie chart and grouped Bar chart on plotly express subplots

How to remove x-axis tick labels in a stacked-and-grouped bar chart using Plotly

How to sort an R Plotly grouped bar chart within groups?

How to label a grouped bar chart using plotly express?

Create a grouped bar chart of sums in plotly

python plotly - stacked + grouped bar chart

plotly: descending order in grouped bar chart

Plotly grouped bar chart from pandas df

How to plot a grouped bar chart from a dataframe with several columns in x?

Change color of each bar in a grouped bar chart plotly to custom colors

How to Arrange the x axis on a Plotly Bar Chart with R

How to make a grouped bar chart

Adding error bars to a grouped R plotly bar chart

plotly grouped bar chart does not show negative values

How to create a grouped bar chart in Altair?

How to plot a line on the top of a grouped bar chart?

How to plot a Stacked and grouped bar chart in ggplot?

How to reorder the groups in a grouped bar-chart

How to create Grouped Bar Chart in Vegalite?

How to create grouped bar chart for situations

How to remove spaces between grouped bar chart

How to plot and annotate a grouped bar chart

How to solve incorrect grouped bar chart in Chrome?

How to flip order of bars in a grouped bar chart?

How to make grouped bar chart interactive?

How to create a grouped stacked bar chart, not facets

Plotly: How to plot a bar & line chart combined with a bar chart as subplots?