title: Legend in subplots() for vertical lines Matplotlib.pyplot Python
body: <p>I am trying to do EDA with the Kaggle dataset <a href="https://www.kaggle.com/datasets/saurav9786/cardiogoodfitness" rel="nofollow noreferrer">link</a></p>
  <p>I made a plot with 3 subplots and have plotted 3 vertical lines on the basis of mean, median and mode. is there any way to show these 3 lines in a legend?</p>
  <p>This is my code</p>
  <pre><code>def plott(data):
      fig, axes = plt.subplots(3, sharex=True, figsize=(15, 15),gridspec_kw={&quot;height_ratios&quot;: (1, 0.2, 0.6)})
      fig.suptitle('Spread of Data for ' + data.name, fontsize=20, fontweight='bold')
      
      sns.histplot(data, kde=True, binwidth=1, ax=axes[0])
      sns.boxplot(x=data, orient='h', ax=axes[1])
      sns.violinplot(x=data, ax=axes[2])
      
      axes[0].set_xlabel('')
      axes[1].set_xlabel('')
      axes[2].set_xlabel('')
  
      axes[0].axvline(data.mean(), color='r', linewidth=2, linestyle='solid')
      axes[0].axvline(data.median(), color='r', linewidth=2, linestyle='dashed')
      axes[0].axvline(data.mode()[0], color='r', linewidth=2, linestyle='dotted')
      axes[1].axvline(data.mean(), color='r', linewidth=2, linestyle='solid')
      axes[1].axvline(data.median(), color='r', linewidth=2, linestyle='dashed')
      axes[1].axvline(data.mode()[0], color='r', linewidth=2, linestyle='dotted')
      axes[2].axvline(data.mean(), color='r', linewidth=2, linestyle='solid')
      axes[2].axvline(data.median(), color='r', linewidth=2, linestyle='dashed')
      axes[2].axvline(data.mode()[0], color='r', linewidth=2, linestyle='dotted')
      
      axes[0].tick_params(axis='both', which='both', labelsize=10, labelbottom=True)
      axes[1].tick_params(axis='both', which='both', labelsize=10, labelbottom=True)
      axes[2].tick_params(axis='both', which='both', labelsize=10, labelbottom=True)
      
      
  
  
  plott(df['Age'])
  </code></pre>
  <p>This is the resulting plot</p>
  <p><a href="https://i.stack.imgur.com/g6cXd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g6cXd.png" alt="enter image description here" /></a>
  Is there a way to add the legend in here in accordance to the 3 vertical lines
  like this with each line type denoting the value?</p>
  <p><a href="https://i.stack.imgur.com/hAqL6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hAqL6.png" alt="enter image description here" /></a></p>
  <p>Also, how to add more values in x axis of all three graphs?
  like make it interval of 5 or 2 years apart?</p>
  <p>Thanks</p>