相关疑难解决方法(0)

在 Altair (Python) 中标记分层图表

我试图在 Altair 中创建两个分层直方图(以及每个直方图的垂直平均标尺)。我想要一个图例来标记这四个。

我正在使用第一个“出生体重 I”数据,可以在此处找到

我的代码(很长,抱歉)看起来像这样:

from altair import datum

# This histogram for baby weights of mothers who dont smoke
dont = alt.Chart(babyData).mark_bar().encode(
    alt.X("bwt-oz:Q", axis=alt.Axis(title='Birth Weight (Ounces)'), bin=True),
    alt.Y('count()', axis=alt.Axis(title='Count'), scale=alt.Scale(domain=[0, 350]))
).properties(
    width=400,
    height=400
).transform_filter(
    datum.smoke == 0,
)

mean = alt.Chart(babyData).mark_rule(color='red').encode(
    x='mean(bwt-oz):Q',
    size=alt.value(4)
).transform_filter(
    datum.smoke == 0
)

dontSmokeChart = dont + mean

# This histogram for baby weights of mothers who smoke
do = alt.Chart(babyData).mark_bar().encode(
    alt.X("bwt-oz:Q", axis=alt.Axis(title='Birth Weight (Ounces)'), bin=True),
    alt.Y('count()', axis=alt.Axis(title='Count'), scale=alt.Scale(domain=[0, 350]))
).transform_filter( …
Run Code Online (Sandbox Code Playgroud)

python altair

3
推荐指数
1
解决办法
3539
查看次数

标签 统计

altair ×1

python ×1