I'm trying desperately to create nice graphics with Matplot, but it's no easy task. To contextualize, I have two series (serie1, serie2). For each
I have 3 Groups (Group1, Group2 and Group3). For each group, I have some theme and values. Each series describes the behaviour of several individuals (G1, G2, G3) through different variables (Theme). The code is :
import pandas as pd
d = {"ThemeA": [25,34,75], "ThemeB": [0,71,18], "ThemeC": [2,0,0], "ThemeD":[1,14,0] }
serie1 = pd.DataFrame(data = d, index=["Groupe 1", "Groupe 2", "Groupe 3"] )
serie1= serie1.loc[:,:].div(serie1.sum(1), axis=0) * 100
d = {"ThemeA": [145,10,3], "ThemeB": [10,1,70], "ThemeC": [34,1,2], "ThemeD":[3,17,27]}
serie2= pd.DataFrame(data = d, index=["Groupe 1", "Groupe 2", "Groupe 3"])
serie2= serie2.loc[:,:].div(serie2.sum(1), axis=0) * 100
Now I would like to make a graph to display the user data :
ax = fig.add_subplot(111)
ax = serie1.plot(kind='barh', ax=ax, width=0.2, stacked=True, position=0, sharex=True,
sharey=True, legend=True, figsize = (6,2))
serie2.plot(kind='barh', ax=ax, width=0.2, stacked=True, position=1.6,
sharex=True, sharey=True, legend=False)
ax.grid(False)
plt.ylim([-0.5, 2.5])
I was able to get the following graph:
But I would like to move the legend to the bottom. If I try to do this,
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05),
fancybox=True, shadow=True, ncol=5)
I get the following output, which has too many labels.
Of course I would like to see each label exactly once in the legend.
If someone has a miracle solution, I'm a taker! Thanks in advance.



NameError: name 'categories_events' is not defined. Please provide a piece of code that can be run.ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), fancybox=True, shadow=True, ncol=5)