Python 通过Altair生成两个图例
我想有两个传说通过牵牛星就像下面的图片。 我创造了“演员计数”的传奇,但我不知道如何生成另一个。我的代码如下:Python 通过Altair生成两个图例,python,python-3.x,altair,Python,Python 3.x,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
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')
以下是牵牛星图库的修改示例,其中包含两个图例:
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')
这是Altair中的默认行为,但您已禁用颜色图例。将
alt.Color('GENDER',legend=None)
更改为alt.Color('GENDER')
以下是牵牛星图库的修改示例,其中包含两个图例:
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')