Python Altair-具有多个变量的刻面线图

问题描述

我有以下一种DataFrame

Marque Annee Modele PVFP           PM
0   A   1   Python  70783.066836    2.067821e+07
1   A   2   Python  75504.270716    1.957717e+07
2   A   3   Python  66383.237169    1.848982e+07
3   A   4   Python  61966.851675    1.755261e+07
4   A   5   Python  54516.367597    1.671907e+07
5   A   1   Sol     66400.686091    2.067821e+07
6   A   2   Sol     74953.770294    1.955218e+07
7   A   3   Sol     66500.916446    1.844078e+07
8   A   4   Sol     62016.941237    1.748098e+07
9   A   5   Sol     54356.008414    1.662684e+07
10  B   1   Python  43152.461787    1.340989e+07
11  B   2   Python  62397.794144    1.494418e+07
12  B   3   Python  1871.135251     2.178552e+06

我试图建立一个方面图,但没有真正成功。我可以垂直合并生成的2个图表。如果您有任何想法一次完成该操作,将不胜感激。

我当前的代码

   chart = alt.Chart(euro).mark_line().encode(
    x='Annee',y='PVFP',color='Modele'
).properties(
    width=150,height=150
).facet(
    facet='Marque',columns=3
)

chart2 = alt.Chart(euro).mark_line().encode(
    x='Annee',y='PM',columns=3
)

chart & chart2

enter image description here

解决方法

执行此操作的一种好方法是使用Fold Transform将两列折叠为一列,然后可以使用| Text | Predicted labels | Probabilities | |--------------------------------------------|------------------|----------------| | Hello World! | A,B,C | [.80,.10,10] | | Have a nice Day! | B,C,A | [.90,.05,05] | | It's a wonderful day in the neighborhood. | C,A,B | [.80,10] | row构面同时使用这两个变量。例如:

column