简体   繁体   中英

Dollar cents axis in Altair

I would like to format the axis in the following plot such that it shows dollar cents instead of fractional dollars.

data = pd.DataFrame({
    'x': np.random.rand(20)
})

alt.Chart(data).mark_tick().encode(
    alt.X('x', axis=alt.Axis(format='$.2f'))
)

You can use labelExpr to add arbitrary characters to the axis labels:

data = pd.DataFrame({
    'x': np.random.rand(20)
})

alt.Chart(data).mark_tick().encode(
    alt.X('x', axis=alt.Axis(labelExpr='datum.value + "p"'))
)

在此处输入图像描述

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