Seaborn 线图:在图中添加线和文本

Seaborn Line Plot : Add Line and Text in the Graph

我想在图表中添加点线和文本。

这是我的原始 sns.plot 代码。

# set figure size
plt.figure( figsize = ( 12, 5))

sns.lineplot( x = 'date',
            y = 'weekpay',
            data = epi_raw_occ_2018_private,
            label = 'Private Workers Wage')

plt.xlabel('time')

我需要这样的图片

提前致谢

如果它固定在 x 轴的特定值。那么应该这样做:

plt.axvline('2020-02-01',linestyle='.')

至于您可以添加的文字:

plt.text('2020-03-01',1100,"this is the text that will be added")

您应该修复第一个数组以匹配所需的 x 轴,然后在 y 轴上没有参数,这样它就可以覆盖整个图表。另一种方法是使用 weekpaymin()max() 值作为 y 轴,以使线条覆盖大部分。最后 linestyle='.' 是使它成为虚线的原因。