У меня есть два столбца в диаграмме. Однако я бы хотел отобразить только одну из надписей в легенде. Пример:
In [190]: import pandas as pd
In [191]: import matplotlib.pyplot as plt
In [192]: import seaborn as sns
In [193]: from matplotlib.colors import ListedColormap
In [194]: my_cmap = ListedColormap(sns.color_palette("GnBu_d", 4).as_hex())
In [195]: df1 = pd.DataFrame([[200, 0.0, 0.0, 0.0], [0.0, 120, 60, 20]], columns=['Total','A', 'B', 'C'])
In [196]: ax = df1.plot(colormap=my_cmap, title='Allocation per bucket', kind='bar', stacked=True, alpha=0.8)
In [197]: ax.title.set_size(30)
In [198]: ax.set_ylabel('Value', fontsize=15)
Out[198]: Text(0,0.5,'Value')
In [199]: ax.set_xticklabels(['Total', 'Split'])
Out[199]: [Text(0,0,'Total'), Text(0,0,'Split')]
In [200]: box = ax.get_position()
In [201]: ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
In [202]: ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), fontsize=13, prop={'size': 13})
Out[202]: <matplotlib.legend.Legend at 0x7f1ce0b4e050>
In [203]: plt.xticks(rotation=0)
Out[203]: (array([0, 1]), <a list of 2 Text xticklabel objects>)
In [204]: plt.show()
Как видите, это приводит к следующей картинке

Я хотел бы удалить Total
из легенды и отображать только A
, B
и C
. Как мне этого добиться?