I'm trying to overlay a legend to this plot but am not sure how to. I want the legend to include the two bar data sets and the two lines. I'd also like, if possible, to extend the dotted lines in the graph so they span the whole width of the figure. I'd appreciate advice on both if you could help.
At the moment I have the following:
import numpy as np
import matplotlib.pyplot as plt
A_Data=np.array([1, 2.3, 1.6, 4.5, 2.7])
B_Data=np.array([ 1.4, 3.3, 2.7, 4.1, 3.9])
N=5
ind = np.arange(N)
width = 0.35
#limit values for horizontal lines
t = 4.0
o = 1.0
#plot
fig, ax = plt.subplots()
plt.title('Test Graph for Stack Overflow')
ax.bar(ind, A_Data, width)
ax.bar(ind+width, B_Data,width)
ax.plot(ind+width/2, [t,t,t,t,t], "r--") #is there a way to have this stretch the whole width
of the figure?
ax.plot(ind+width/2, [o,o,o,o,o], "k--")
plt.xticks(ind + width / 2, ('one', 'two', 'three', 'four', 'five'))
plt.xlabel('X-Axis')
plt.ylabel('Y-Axis')
plt.legend(loc='best') #want this to show bars and lines in legend
fig.savefig("Test graph for stack overflow Q", dpi = 300)