0

Consider the code in the example which is

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

fig = px.scatter(df, x="gdpPercap", y="lifeExp", hover_name="country", log_x=True)
fig.show()

and produces

enter image description here

Is it possible that the ticks in the x axis would show 2000, 20k and so on instead of 2, and the same for 3, 4 ... ?

user171780
  • 2,243
  • 1
  • 20
  • 43

1 Answers1

1
import plotly.express as px
import numpy as np
import pandas as pd

df = px.data.gapminder().query("year == 2007")

fig = px.scatter(df, x="gdpPercap", y="lifeExp", hover_name="country", log_x=True)
fig.update_layout(
    xaxis={
        "tickmode": "array",
        "tickvals": pd.to_numeric(
            [f"{n:.1g}" for n in np.geomspace(1, df["gdpPercap"].max(), 15)]
        ),
    }
)

enter image description here

Rob Raymond
  • 29,118
  • 3
  • 14
  • 30