【发布时间】:2022-08-18 18:06:16
【问题描述】:
我正在使用劳工统计局的数据制作分层图表,并且由于我要发布图表,因此我需要引用数据源。我需要在图表底部添加一条线,说明“来源:劳工统计局。截至 2022 年 7 月的数据。”我可以添加标题和副标题,但似乎没有脚注/源代码行的选项。有什么解决方法吗?
import pandas as pd
import pandas_datareader.data as pdr
import datetime
import altair as alt
start = datetime.datetime (2020, 1, 1)
end = datetime.datetime (2022, 7, 10)
df = pdr.DataReader(\'UNRATE\', \'fred\', start, end)
df = df.rename(columns={\'UNRATE\':\'Unemployment Rate\'})
df[\"Date\"] = df.index
df[\'Prepandemic Rate\'] = 3.5
source = df
line = (
alt.Chart(source)
.mark_line(point=False, strokeWidth=2, color=\'blue\')
.encode(x=\"Date\", y=\"Unemployment Rate\")
)
line2 = (
alt.Chart(source)
.mark_line(point=False, strokeWidth=2, color=\'red\')
.encode(x=\"Date\", y=\"Prepandemic Rate\")
)
alt.layer(line, line2).properties(
width=300, height=300, title={
\"text\":\'Unemployment Rate\',
\"subtitle\":[\'Seasonally adjusted\']
},
).configure_title(
anchor= \'start\'
)
注意:我看到了这个问题 (How to add a Text Footer to an Altair graph?),但我似乎无法让 concat 函数在我的分层图表上工作。