简体   繁体   中英

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" 
)

示例图片

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:

在此处输入图像描述

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM