import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
labels = ['有电梯', '无电梯']
sizes = [60, 40]
colors = ['#66b3ff', '#ff9999']
explode = (0.05, 0)
plt.figure(figsize=(8, 6), dpi=100)
patches, texts, autotexts = plt.pie(
sizes,
explode=explode,
labels=labels,
colors=colors,
autopct='%1.1f%%',
startangle=90,
textprops={'fontsize': 12}
)
plt.title('市房屋有无电梯分布图', fontsize=16, pad=20)
for autotext in autotexts:
autotext.set_color('white')
autotext.set_fontsize(12)
plt.legend(
title="电梯配置",
loc="upper left",
bbox_to_anchor=(1, 0, 0.5, 1)
plt.axis('equal')
plt.savefig('3.1.png', bbox_inches='tight', dpi=300)
plt.show()