【问题标题】:Generate two legends via Altair通过 Altair 生成两个图例
【发布时间】:2021-02-14 19:37:34
【问题描述】:

我想通过 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

我创建的图表是这样的:

【问题讨论】:

    标签: python python-3.x altair


    【解决方案1】:

    这是 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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-03
      • 2020-07-28
      • 1970-01-01
      • 2018-10-18
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      • 2021-02-09
      相关资源
      最近更新 更多