I believe the closes you'll get is logartihmic axes :
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()
This has been bugging me for a while, here's the best solution I've found:
TLDR, you can use HTML formatting to make sure the exponent is a superscript and use array
mode to pass strings for the tick labels to plotly.
import plotly.express as px
import numpy as np
df = px.data.gapminder().query("year == 2007")
fig = px.scatter(df, x="gdpPercap", y="lifeExp", hover_name="country", log_x=True)
tickvals = np.logspace(3,6, num=4)
print(tickvals)
def format_tick(n: float):
m, e = f"{n:.0e}".split("e")
e = int(e)
return f"{m} x 10<sup>{e}</sup>"
ticktext = [format_tick(t) for t in tickvals]
print(ticktext)
fig.update_layout(
xaxis = dict(
tickmode = 'array',
tickvals = tickvals,
ticktext = ticktext,
)
)
fig.show()
I was also in a search for this feature, and found the solution in this other answer:
https://stackoverflow.com/a/56742105/418875
You should set exponentformat
to the power
option. This will print the ticks as shown below:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.