Home > front end >  Legend in subplots() for vertical lines Matplotlib.pyplot Python
Legend in subplots() for vertical lines Matplotlib.pyplot Python

Time:07-16

I am trying to do EDA with the Kaggle dataset enter image description here 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?

enter image description here

Also, how to add more values in x axis of all three graphs? like make it interval of 5 or 2 years apart?

Thanks

CodePudding user response:

Give the axvlines a "label" value, then call plt.legend after plotting it.

Example:

import matplotlib.pyplot as plt

plt.plot([1,2,3],[1,2,3],label="Test")
plt.axvline(x=0.22058956, label="Test2", color="red")
plt.legend()

Output:enter image description here

  • Related