Don99
Don99

Reputation: 229

How to change x-axis label of graph to be multiples of 10?

I am using plotly library to plot my line chart.

Currently my x-axis has a limit from 0 to 10G (10 Billion) with equal divisions / intervals.

fig.update_xaxes(visible=True, range=[0,10000000000])

Is there any way I can change the x-axis label to increase in multiples of 10 like the image below instead of having equal intervals?

enter image description here

Upvotes: 2

Views: 370

Answers (1)

vestland
vestland

Reputation: 61104

If you're looking for built-in options:

fig.update_xaxes(type="log")

...will give you this:

enter image description here

...instead of this:

enter image description here

Complete code:

'

import plotly.graph_objects as go
import plotly.express as px
df = px.data.gapminder().query("year == 2007")

fig = go.Figure()

fig.add_trace(go.Scatter(mode="markers", x=df["gdpPercap"], y=df["lifeExp"] ))

fig.update_xaxes(type="log")
fig.show()

Upvotes: 1

Related Questions