You may call
handles, labels = ax.get_legend_handles_labels() ax.legend(handles[::-1], labels[::-1], title='Line', loc='upper left')
import numpy as np import matplotlib.pyplot as plt np.random.seed(2016) C0 = list('ABCDEF') C2 = np.random.randint(20000, size=(len(C0), 3)) width = 1.0 C1 = ['foo', 'bar', 'baz'] ind = np.linspace(-width, width, len(C1)) colorsArr = plt.cm.BuPu(np.linspace(0, 0.5, len(C2))) fig = plt.figure(figsize=(11,11)) ax = fig.add_subplot(1, 1, 1) prevBar = 0 for height, color, label in zip(C2, colorsArr, C0): h = ax.bar(ind, height, width, bottom=prevBar, color=color, label=label) prevBar = prevBar + height plt.ylabel('Home Category') plt.title('Affinity - Retail Details(Home category)') # positions of the x-axis ticks (center of the bars as bar labels) tick_pos = [i+(width/2.0) for i in ind] # set the x ticks with names plt.xticks(tick_pos, C1) plt.yticks(np.arange(0,70000,3000)) handles, labels = ax.get_legend_handles_labels() ax.legend(handles[::-1], labels[::-1], title='Line', loc='upper left') plt.show()

unutbu
source share