简体   繁体   English

Altair 中的美元美分轴

[英]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.我想在以下 plot 中格式化轴,使其显示美元美分而不是小数美元。

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:您可以使用labelExpr将任意字符添加到轴标签:

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

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

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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