I'm trying to get labels left-aligned and values right-aligned in the legend. In below code, I've tried with format method, but the values are not properly aligned.
Any hint/suggestions is greatly appreciated.
import matplotlib.pyplot as pl
# make a square figure and axes
pl.figure(1, figsize=(6,6))
labels = 'FrogsWithTail', 'FrogsWithoutTail', 'DogsWithTail', 'DogsWithoutTail'
fracs = [12113,8937,45190, 10]
explode=(0, 0.05, 0, 0)
pl.pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
pl.title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})
legends = ['{:<10}-{:>8,d}'.format(labels[idx], fracs[idx]) for idx in range(len(labels))]
pl.legend(legends, loc=1)
pl.show()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…