I have the following graph in in which there is the average bpm in relation to the listening day. I want to plot near the point the exact value of mean. How can I do it?
What I expect in output is:
This is the code I wrote:
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)
CodePudding user response:
You can use plt.text(x, y, s)
where s
is the text you want to display and x
and y
are the text coordinates.
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