2

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.

nilsinelabore
  • 4,143
  • 17
  • 65
  • 122
  • 1
    @nilsinlabore Don't forget your [data samples](https://stackoverflow.com/questions/63163251/pandas-how-to-easily-share-a-sample-dataframe-using-df-to-dict/63163254#63163254) – vestland May 21 '21 at 06:40

1 Answers1

3
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()
vestland
  • 55,229
  • 37
  • 187
  • 305