简体   繁体   中英

Altair python - how to align x axis (=0) for charts within a for

I want to align al charts generated in a loop, but x axis do not start at the same vertical line, because of the 'y' labels. See below:

在此处输入图像描述

for campo in [col for col in nomina.columns if col!= 'Fecha ingreso']:
    a = alt.Chart(nomina[[campo]]).mark_bar().encode(
        x='count(' + campo + '):Q',
        y=alt.Y('' + campo + ':N', sort='-x')
    )
    display(a.resolve_scale(x='shared'))

and I would like to see like this:

在此处输入图像描述

already figured it out. I just had to add charts in a list, then use alt.vconcat(mylistcharts)!

charts = []
for campo in [col for col in nomina.columns if col!= 'Fecha ingreso']:
    a = alt.Chart(nomina[[campo]]).mark_bar().encode(
        x='count(' + campo + '):Q',
        y=alt.Y('' + campo + ':N', sort='-x')
    )
    charts.append(a.resolve_scale(x='shared'))
alt.vconcat(*charts)

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