users = ['user1', 'user2', 'user3', 'user4', 'user5', 'user6', 'user7', 'user8', 'user9', 'Другие']
sizes = [15, 30, 45, 10, 23, 55, 22, 56, 11, 99]
plt.gca().axis("equal")
pie = plt.pie(sizes, startangle=90)
porcent = 100. * np.array(sizes) / sum(sizes)
labels = ['{0} - {1:1.2f} %'.format(i, j) for i, j in zip(users, porcent)]
print(labels)
print(sizes)
sort_legend = True
if sort_legend:
patches, labels, dummy = zip(*sorted(zip(pie[0], labels, sizes),
key=lambda x: x[2],
reverse=True))
plt.legend(patches, labels, bbox_to_anchor=(1, 0.5), loc="center right", fontsize=10,
bbox_transform=plt.gcf().transFigure)
plt.subplots_adjust(left=0.0, bottom=0.1, right=0.45)
plt.show()
如何使“其他”元素位于图例的末尾而不是其他任何地方,具体取决于其值