Decimal precision of xticks after zoom in plot plotly

I’m working on a project i need to plot a line chart.
code is below

import plotly.graph_objects as go
import numpy as np

fig = go.Figure()

# Example data
x = np.arange(0,58)
y = np.random.random_integers(0,10,58)

# Add scatter plot
fig.add_trace(go.Scatter(x=x, y=y, mode='lines+markers'))

fig.show()

Issue is when i zoom in plot it’s xticks decimal points varies as shown in figures


decimal points like 19.6 , 19,65 , 19.7 ,19.75 ,19.8 ,19.85 ,19.9
but i need same decimal precision like 19.60, 19.65, 19.70,19.75 ,19.80 ,19.85 ,19.90

I have used tickformat='.2f' but it stops zooming and bound xticks to two decimal points

I need more zoom in with same decimal precision


ticks should like 19.690, 19.695, 19.700, 19.705, 19.710

and same for more zoom in

If someone can help i’ll be very thankful

Hi @zeeshanch2732 ,

As far as I know, you need to use tickformatstops.
With this attribute, you can define certain tickformat value for certain dtickrange.

import plotly.graph_objects as go
import numpy as np

fig = go.Figure()

# Example data
x = np.arange(0,58)
y = np.random.random_integers(0,10,58)

# Add scatter plot
fig.add_trace(go.Scatter(x=x, y=y, mode='lines+markers'))

# define tickformat for certain dtickrange
fig.update_xaxes(tickformatstops = [
					{'dtickrange':[0, 0.009], 'value': ".4f"},
					{'dtickrange':[0.009,0.09], 'value': ".3f"},
					{'dtickrange':[0.09,0.9], 'value': ".2f"}
				])
fig.show()

Hope this help.

1 Like