Black Lives Matter. Please consider donating to Black Girls Code today.

Misalignment of bar plot x axis

I’m doing an overlay plot of a scatter and bar plot but for some reason the bar plot is being inconsistent, I think, on the xaxis.

I’ve attached some images to explain - these include the plotting code, an example of the data being used, and the output.

As you can see the scatter points are exatctly at their indicated x positions, however the bar plots seem to vary. I understand that where a bar goes on the x-axis might vary (middle, one of the edges, width can effect this) however I would at least expect this to be consistent.

The bar at x = 4 looks great: bang on in the middle, but the other two are off by a bit - how come?

Thanks,
Z
code
df

I just had the same issue. Use

fig.update_layout(barmode='overlay')