饼图的切片一般只显示比例,不显示具体数字。如果需要在饼图上显示数字,可以采用以下两种方法:
import matplotlib.pyplot as plt labels = ['A', 'B', 'C', 'D'] sizes = [10, 20, 30, 40] fig1, ax1 = plt.subplots() ax1.pie(sizes, labels=labels, autopct='%1.1f%%') ax1.axis('equal') plt.show()
import matplotlib.pyplot as plt labels = ['A', 'B', 'C', 'D'] sizes = [10, 20, 30, 40] fig, ax = plt.subplots() ax.pie(sizes, labels=labels, autopct='%1.1f%%', wedgeprops={"edgecolor": "white", 'linewidth': 3, 'linestyle': 'solid', 'antialiased': True}) centre_circle = plt.Circle((0,0),0.70,fc='white') fig = plt.gcf() fig.gca().add_artist(centre_circle) ax.axis('equal') plt.show()