Format ticks: i.e. 200 to 20. One zero less

Hi community,

I want the plot axes tick to be formatted for example from ‘200’ to ‘20’. My code is:

dx, dz = 100, 100
x = np.arange(0, 60000, dx)
z = np.arange(0, 30000, dz)

[zz, xx]= np.meshgrid(z, x, indexing='ij')

vel = 1000 + 0.032 * zz

fig = px.imshow(vel, labels=dict(x="x[km]", y="z[km]", color="Velocity (m/s)"),
                color_continuous_scale='RdBu',
)

fig.update_layout(xaxis_title='x [km]', yaxis_title='z [km]', title='Raytrace')

The result plot is:

I want the plot axes to have a zero less. For example: the y-axis ticks be [0, 5, 10, 15, …] instead of [[0, 50, 100, 150, …]]

If anyone can help me out here, I’ll be very greatful.

Thanks

hi @esia2019 ,

You could add a fixed range like this:

fig.update_xaxes(
    tickmode='array',
    tickvals=[100*i for i in range(6)],
    ticktext=[10*i for i in range(6)])

EDIT: according to this stackoverflow post, you can obtain the autorange the following code snippet:

full_fig = fig.full_figure_for_development(warn=False)
print(full_fig.layout.xaxis.range)

This worked for me, but the kaleido package has to be installed.

1 Like