在 Altair 中将轴缩放为科学记数法

Scale an axis to scientific notation in Altair

如何在 altair 库中将垂直轴缩放为科学记数法。例如,在下图中,将有 5e10 而不是 50,000,000,000

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

您需要设置的一个选项是 format 使用 d3-format 代码:

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

".1e"e前的数字说明要显示的位数: