1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import matplotlib.pyplot as plt
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' fracs = [15, 30, 45, 10]
fig, axs = plt.subplots(2, 2)
axs[0, 0].pie(fracs, labels=labels, autopct='%1.1f%%', shadow=True)
axs[0, 1].pie(fracs, labels=labels, autopct='%.0f%%', shadow=True, explode=(0, 0.1, 0, 0))
patches, texts, autotexts = axs[1, 0].pie(fracs, labels=labels, autopct='%.0f%%', textprops={'size': 'smaller'}, shadow=True, radius=0.5)
plt.setp(autotexts, size='x-small') autotexts[0].set_color('white')
patches, texts, autotexts = axs[1, 1].pie(fracs, labels=labels, autopct='%.0f%%', textprops={'size': 'smaller'}, shadow=False, radius=0.5, explode=(0, 0.05, 0, 0)) plt.setp(autotexts, size='x-small') autotexts[0].set_color('white')
plt.show()
|