在点 matplotlib 附近绘制值

Plot value near point matplotlib

我有下图,其中有与收听日相关的平均 bpm。我想在该点附近绘制均值的确切值。我该怎么做?

This is the image

我期望的输出是:

expected output

这是我写的代码:

df = pd.read_csv(f, encoding = "ISO-8859-1", sep = ';')
bpmFriday= df.tempo

x = df .date.iloc[0]    
bpmMean = bpmFriday.mean()

first= plt.figure(figsize=(10,5))
plt.title('BPM mean (Friday)')
plt.scatter(x, bpmMean )
plt.xticks(rotation=45)

您可以使用plt.text(x, y, s),其中s是您要显示的文本,xy是文本坐标。

import matplotlib.pyplot as plt

x = '2021-12-25'
bpmMean = 420

first= plt.figure(figsize=(10,5))
plt.title('BPM mean (Friday)')
plt.scatter(x, bpmMean )
plt.xticks(rotation=45)

# plt.annotate(s=bpmMean, xy=(x, bpmMean+.5))

plt.text(x=x, y=bpmMean+0.5, s=bpmMean) # y=bpmMean+0.5 for readibility