简体   繁体   English

有没有办法在Altair标准化堆积条形图中显示百分比(0-100%)?

[英]Is there a way to show percentage (0-100%) in an Altair normalized Stacked Bar Chart?

Is there a way to show 0% - 100% instead 0.0 - 1.0 in an Altair Normalized Stacked Bar Chart ? 有没有办法在Altair标准化堆积条形图中显示0%-100%而不是0.0-1.0?

I tried 我试过了

x=alt.X('sum(yield)', stack="normalize", scale=alt.Scale(range=[0, 100]))

but this does not give the expected result. 但这不能给出预期的结果。

import altair as alt
from vega_datasets import data

source = data.barley()

alt.Chart(source).mark_bar().encode(
    x=alt.X('sum(yield)', stack="normalize"),
    y='variety',
    color='site'
)

You can use the axis format argument along the axis in question. 您可以沿所讨论的轴使用轴格式参数。 For example: 例如:

import altair as alt
from vega_datasets import data

source = data.barley()

alt.Chart(source).mark_bar().encode(
    x=alt.X('sum(yield)', stack="normalize", axis=alt.Axis(format='%')),
    y='variety',
    color='site'
)

在此处输入图片说明

Altair uses d3 format codes; Altair使用d3格式代码; more information on these is available here . 有关这些的更多信息,请参见此处

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

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