How to increase x ticks in plotly.express histogram

Viewed 564

I have a Plotly graph with code:

import plotly.express as px
fig = px.histogram(df.col1, width= 1500, height= 700)
fig.show()

and the plot looks like this: enter image description here

Is there a way I can increase the x tick markings to every 2 or 5 interval?

Tried:

import plotly.express as px
fig = px.histogram(df.col1, width= 1500, height= 700)
fig.update_traces(xbins_size = 0.5)
fig.show()

and got enter image description here

The issue is that I would like to increase x ticks to every 5 to improve visibility while capturing the range of 0-50. But the interval is still 10.

1 Answers
fig.update_traces(xbins_size = <float>)

For a plot built with:

fig = px.histogram(x=np.random.randn(500))

enter image description here

You can use:

fig.update_traces(xbins_size = 0.5)

And get:

enter image description here

Now, compare this with:

fig.update_traces(xbins_size = 1)

Which will give you:

enter image description here

Complete code:

import plotly.express as px
import numpy as np
np.random.seed(123)
fig = px.histogram(x=np.random.randn(500))
fig.update_traces(xbins_size = 0.5)
fig.show()
Related