You need changes to a few place to get the labels:
C1=candlestick(ax,quotes,width = 0.5, colorup = "green", colordown = "red")
C2=candlestick(ax,quotes2, width = 0.2, colorup = "grey", colordown = "black")
ax.xaxis_date()
ax.autoscale_view()
ax.legend((C1[1][0],C2[1][0]), ('label1', 'label2'),loc=3)
The problem is that we have colorup
and colordown
here, you can't easily put them both in the legend (well, you may be able to, that will be quite complex).
So why C2[1][0]
? Because this is what C1
is:
In [5]:
C1
Out[5]:
([<matplotlib.lines.Line2D at 0x76b3c90>,
<matplotlib.lines.Line2D at 0x759d3b0>,
<matplotlib.lines.Line2D at 0x759dab0>,
<matplotlib.lines.Line2D at 0x75a61d0>],
[<matplotlib.patches.Rectangle at 0x76b3df0>,
<matplotlib.patches.Rectangle at 0x759d590>,
<matplotlib.patches.Rectangle at 0x759dc90>,
<matplotlib.patches.Rectangle at 0x75a63b0>])
If you have other plot that will follow the candlestick plots:
plt.hlines(1.10, plt.xlim()[0], plt.xlim()[1], label='Other Plot') #such as an horizontal line
#And may be other plots.
handles, labels = ax.get_legend_handles_labels()
import operator
hl = sorted(zip(handles, labels),
key=operator.itemgetter(1)) #sort is optional
handles2, labels2 = zip(*hl)
handles2=list(handles2)+[C1[1][0],C2[1][0]] #put the candel plot legend to the end
labels2=list(labels2)+['label1', 'label2'] #put the candel plot legend to the end
ax.legend(handles2, labels2, loc=8)
Taking from the documents.