我正在尝试将pyplot数字保存到.png
文件。
问题是,图形显示在屏幕上,但文件是空白页!
import matplotlib.pyplot as plt
# Pie plotting code from Matplotlib.org
plt.figure(figsize=(12,9))
labels = defaults.grade
sizes = defaults.grade_pct_of_total
colors = ['yellowgreen', 'gold', 'lightskyblue',
'lightcoral','blue','red','orange']
explode = (0.1, 0.1, 0.1, 0.1,0.1,0.1,0.1)
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=90)
plt.title('Default contribution % \n\n')
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.show()
plt.savefig('Default Contributions by Grade.pdf', bbox_inches='tight')
请注意
defaults.grade
是一个列表['A','B','C','D'...]
defaults.grade_pct_of_total
是一系列花车答案 0 :(得分:2)
plt.show()
也会清除你的画布。只需将其删除或运行plt.savefig
,plt.show
即可解决问题。