通过 Altair 生成两个图例

Generate two legends via Altair

我想通过 Altair 有两个图例,如下图所示。

我创造了“演员伯爵”的传奇,但我不知道如何生成另一个。我的代码如下:

plot = base.mark_circle(
   opacity=0.8,
   stroke='black',
   strokeWidth=1
).encode(
   alt.X('TYPE:O'),
   alt.Y('index:N',
          sort= movies_order
          ),
   alt.Size('count(index):Q',
   scale=alt.Scale(range=[0,4500]),
   legend=alt.Legend(title='Count of actors', symbolFillColor='white')),
   alt.Color('GENDER', legend=None)
   #complete this
).properties(
   width=350,
   height=880

而我创建的图表是这样的:

这是 Altair 中的默认行为,但您已禁用颜色图例。将 alt.Color('GENDER', legend=None) 更改为 alt.Color('GENDER')

这里是 Altair 画廊的修改示例,有两个图例:

import altair as alt
from vega_datasets import data

source = data.cars()

alt.Chart(source).mark_circle().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
    size='Cylinders')