altair 删除或抑制自动生成的绘图图例

altair remove or suppress automatically generated plot legend

使用 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()

生成此图:

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

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

他们在这里将图例设置为 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),
)