koshachok
koshachok

Reputation: 510

Scale an axis to scientific notation in Altair

How can I scale my vertical axis to scientific notation in altair library. On the image below for example, there will be 5e10 instead of 50,000,000,000.

alt.Chart(df).mark_area().encode(
    x=alt.X("date:T"),
    y=alt.Y("time:Q"),
    color="type" 
)

Example image

Upvotes: 1

Views: 1296

Answers (1)

koshachok
koshachok

Reputation: 510

An option you need to set is format using a d3-format code:

alt.Chart(df).mark_area().encode(
    x=alt.X("date:T"),
    y=alt.Y("time:Q", axis=alt.Axis(tickCount=10, format=".1e"),
    color="type" 
)

The number before e in ".1e" describes the number of digits to show :

enter image description here

Upvotes: 2

Related Questions