如何显示曲线旁边的最后一个Y轴值? [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我试图找出如何让我的图表显示曲线旁边的时间序列中的最新(最后)Y轴值。目前我有以下图表。我尝试过使用'plt.text'但这意味着我手动输入值而不是python在生成图表时自动显示我。

enter image description here

curve_name = 'G_H_TTF-Monthly.USD'
TTF = get_forward_curve_history(name=curve_name, start_date='2018-01-01', 
end_date=date)

NBP_TTF_Q1 = NBP.loc['2020-01-01':'2020-03-31'].mean() - TTF.loc['2020-01- 
01':'2020-03-31'].mean()

NBP_TTF_Q1.plot()


 plt.text(6,40,'0.66')


plt.gca().legend(('NBP_TTF_Q1','Jul19','Jun/Jul18','Jun/Jul19'))
plt.grid()
plt.show()

虽然我会期待这样的事情(借口可怜的笔写技巧):

enter image description here

python matplotlib plot text annotate
1个回答
0
投票

尝试使用时间序列数据中的最后一个值

plt.text(6, 40, NBP_TTF_Q1[-1])

© www.soinside.com 2019 - 2024. All rights reserved.