【发布时间】:2020-06-28 01:24:28
【问题描述】:
考虑以下示例:
import altair as alt
from vega_datasets import data
df = data.seattle_weather()
temp_max = alt.Chart(df).mark_line(color='blue').encode(
x='yearmonth(date):T',
y='max(temp_max)',
)
temp_min = alt.Chart(df).mark_line(color='red').encode(
x='yearmonth(date):T',
y='max(temp_min)',
)
temp_max + temp_min
在结果图表中,我想添加一个图例,显示蓝线显示最高温度,红线显示最低温度。实现这一目标的最简单方法是什么?
我看到(例如在这个问题的解决方案中:Labelling Layered Charts in Altair (Python))如果在编码中设置了 color 或 size 或因此,通常使用分类列,但这在这里是不可能的,因为我正在绘制整个列,并且标签应该是列名(现在显示在 y 轴标签中)。
【问题讨论】: