简体   繁体   中英

Altair combine two charts

I am trying to plot/combine two charts on Altair, but only one of the chart is actually showing with the expected data. The second chart doesn't show.

The second chart is blank

Code below:

import altair as alt
import pandas as pd

data = pd.read_csv('sampledata.csv')

alt.Chart(data).transform_fold(
    ['life', 'gdp'], as_=['key', 'value']
).properties(
    width=250,
    height=250
).mark_line().encode(
    x='Year:O',
    y='sum(value):Q',
    color='region:N'
).facet(
    row='key:N'
)

Image below:

在此处输入图像描述

If life is referring to life expectancy, the reason you don't see the lines is the lower facet is likely that the sum of these columns is much lower than that of the GDP sum. Try to set your y-axes to be independent by appending .resolve_scale(y='independent') to you chart spec.

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