I'm coding in Python and testing Matplotlib. I'm trying to add multiple legends because I have 2 pie charts. Using this http://matplotlib.org/users/legend_guide.html I got 2 multiple legends, but with the same colours. For every pie chart, I have 2 differents colors, so I want the same colours for their respectives legends.
Also, is it possible to put the legend closer to the border of the window? Because the legend is a long phrase and I don't want the second legend in the middle of the screen.
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
#def pieChart()
# Data to plot
labels = 'Participaram', 'Não participaram'
sizes = [215, 130]
colors = ['gold', 'yellowgreen']
explode = (0.1, 0) # explode 1st slice
labels2 = 'Só visualizam dúvidas alheias', 'Mandaram e visualizam'
sizes2 = [215, 130]
colors2 = ['lightskyblue', 'lightcoral']
explode2 = (0, 0.08) # explode 1st slice
# Plot
plt.pie(sizes, explode=explode, colors=colors2,autopct='%1.1f%%', shadow=True, startangle=90, center = (-2,0))
plt.pie(sizes2, explode=explode2, colors=colors,autopct='%1.1f%%', shadow=True, startangle=45, center = (2,0))
first_legend = plt.legend(labels,loc = 2)
ax = plt.gca().add_artist(first_legend)
second_legend = plt.legend(labels2,loc = 4,ncol=1)
plt.axis('equal')
plt.show()


