Plot of a discrete distribution

That is allowed, but somehow the bars do not inherit the color of scatter.
So, color=scatter.marker.color does not appear to have any effect:

import numpy as np
from scipy import stats
import plotly.graph_objs as go

fig = go.FigureWidget()
xs = np.arange(51)
ys = stats.binom.pmf(xs, n=50, p=0.3)
scatter = fig.add_scatter(x=xs, y=ys, mode='markers')
fig.add_bar(x=xs, y=ys, marker = dict(color=scatter.marker.color, opacity=0.3))
fig.layout = dict(showlegend = False, bargap=0.75, barmode='overlay', width = 800)
fig

will produce:

If I then change the name to dots but keep scatter.marker.color:

fig = go.FigureWidget()
xs = np.arange(51)
ys = stats.binom.pmf(xs, n=50, p=0.3)
dots = fig.add_scatter(x=xs, y=ys, mode='markers')
fig.add_bar(x=xs, y=ys, marker = dict(color=scatter.marker.color, opacity=0.3))
fig.layout = dict(showlegend = False, bargap=0.75, barmode='overlay', width = 800)
fig

I get what I want:

So, I think scatter gets initialized when fig is called… or something like that. In my case it remembered the scatter attributes from the previous call. Indeed when I place fig.add_bar(x=xs, y=ys, marker = dict(color=scatter.marker.color, opacity=0.3)) in a different cell (after I’ve run fig) I get the right output. It is not very elegant though to have bits of code pertaining to the same plot in different cells, and I don’t know how (aside from using dictionaries) this can be done in a loop (as shown in the first piece of code above).

Maybe I’m missing something.