【问题标题】:altair remove or suppress automatically generated plot legendaltair 删除或抑制自动生成的图例
【发布时间】:2019-04-03 16:49:27
【问题描述】:

使用 altair 包时,我注意到创建图表时还会生成图例。以下代码:

import altair as alt
from vega_datasets import data
alt.renderers.enable('notebook')

cars = data.cars()

alt.Chart(cars).mark_circle().encode(x='Horsepower', 
                                     y='Miles_per_Gallon',
                                     color='Origin',
                                     tooltip=['Name', 'Origin', 'Horsepower', 'Miles_per_Gallon']).interactive()

生成此图:

我的问题:有什么方法可以在图形输出中抑制这个图例?

【问题讨论】:

    标签: python jupyter-notebook vega vega-lite altair


    【解决方案1】:

    altair 模块的文档中有一个示例。你可以找到它here

    他们在这里将 Legend 设置为 None,这会删除图例。

    这是他们的示例代码:

    import altair as alt
    from vega_datasets import data
    
    iris = data.iris()
    
    alt.Chart(iris).mark_point().encode(
        x='petalWidth',
        y='petalLength',
        color=alt.Color('species', legend=None),
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-29
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 2011-06-14
      • 2015-04-11
      相关资源
      最近更新 更多