I want a red line to go across my bar charts without scrunching the bars together. The red line should go across both charts at the average. This is just an MRE. The chart I’m actually using is 7 dropdowns the vary in size so the bars not scrunching together is very important to me.
import plotly.graph_objects as go
x1 = [‘Alfred’, ‘Bob’, “Cory”, “Dave”, “Eric”, "Freddy]
x2 = [‘Annie’, “Barbara”]
y1 = [20, 30, 25, 40, 40, 50]
y2 = [50, 70]
average = 47
fig = go.Figure()
fig.add_trace(go.Bar(x=x1, y=y1))
fig.add_trace(go.Bar(x=x2, y=y2, visible=False))
fig.add_shape(
type=‘line’, line=dict(dash=‘dot’, color=‘red’),
x0=-1, x1=len(x1), y0=average, y1=average
)
fig.update_layout(
updatemenus=[go.layout.Updatemenu(
active=0,
buttons=list([
dict(label=“1”,
method=“update”,
args=[{‘visible’:[False,True]}]),
dict(label=“2”,
method=“update”,
args=[{‘visible’:[True,False]}]),]))])