title: Label a line graph above each point on the line with its value python
body: <p>I have a plot with a bar and line graph on different y axes. I need to label the line graph with its values just above each point on the line. I've tried something like this</p>
  <pre><code>for p in ax2.patches:
      w,h = p.get_width(), p.get_height()
      x = p.get_x()
      ax2.text(x + w/2, h * 1.1, 
               f'{h}', va='center', ha='center')
  </code></pre>
  <p>which is a structure I used to label the bar graph. I also tried the example listed on this page <a href="https://queirozf.com/entries/add-labels-and-text-to-matplotlib-plots-annotation-examples" rel="nofollow noreferrer">https://queirozf.com/entries/add-labels-and-text-to-matplotlib-plots-annotation-examples</a>, but couldn't figure it out since the examples are just using two series to generate the plot.</p>
  <p>My code and graph is as follows:</p>
  <pre><code>import matplotlib.pyplot as plt
  import pandas as pd
  
  width=.7
  
  t=pd.DataFrame({'bars':[3.4,3.1,5.1,5.1,3.8,4.2,5.2,4.0,3.6],'lines':[2.4,2.2,2.4,2.1,2.0,2.1,1.9,1.8,1.9]})
  ax1 = t['bars'].plot(kind='bar',width=width,color='lightgrey')
  ax2 = t['lines'].plot(secondary_y=True, color='red')
  ax1.plot(label='bars')
  ax2.plot(label='lines')
  lines,labels=ax1.get_legend_handles_labels()
  lines2,labels2=ax2.get_legend_handles_labels()
  ax2.legend(lines+lines2,labels+labels2)
  
  ax1.yaxis.grid(linestyle='dashed')
  ax1.set_axisbelow(True)
  ax1.set_xticklabels(('1','2','3','4','5','6','7','8','9'))
  ax1.set_ylim(0,6)
  ax1.set_ylabel('title1')
  ax2.set_ylim(0, 2.5)
  ax2.set_ylabel('title2')
  
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/cJYMa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cJYMa.png" alt="pic" /></a></p>