How to format bar chart yearly x-axis to not contain floats

76 Views Asked by At

What causes the x-axis to have Year numbers in between the bars and the 0.5 attached to the Population Year

ru = px.bar(wakel, x = "Population Year", y = "Population", color = "City")
ru.show()

enter image description here

1

There are 1 best solutions below

0
On

To avoid this behaviour (and rather than having to modify your data beforehand) you can tell plotly to treat the x axis values as 'categorical' by updating the layout for the x axes.

ru.update_xaxes(type='category')