'Plot legend after loop with additional labels
I have a plot with multiple plt.vlines printed both through a for loop and out of it.
with open('textfile.txt', 'r') as f:
for line in f:
element = line.rstrip('\n')
x_value = [1,2,3,4,5]
if element == 101:
plt.vlines(x_value, color='b', ymin=0.03, ymax=0.035, linestyle='-', label='This label', lw=1.8)
else:
plt.vlines(x_value, color='b', ymin=0.03, ymax=0.035, linestyle='-', lw=1.8)
plt.vlines(6, color='r', ymin=0.03, ymax=0.035, linestyle='-', label='This other label', lw=1.8)
plt.legend(loc='upper left', fontsize=16, framealpha=1)
But I want to plot the legend for both named labels, while as it is now, the plot shows only the label called at last.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
