我有以下代码:
import pandas as pd
import matplotlib
matplotlib.style.use('ggplot')
df = pd.DataFrame({ 'sample1':['foo','bar','bar','qux'], 'score':[5,9,1,7]})
sum_df = df.groupby("sample1").sum()
pie = sum_df.plot(kind="pie", figsize=(6,6), legend = False, use_index=False, subplots=True, colormap="Pastel1")
这是制作饼图的方法,我想要做的是将其保存到文件中。但为什么失败了呢?
fig = pie.get_figure()
fig.savefig("~/Desktop/myplot.pdf")
我遇到了这个错误:
'numpy.ndarray' object has no attribute 'get_figure'
DataFrame.plot()
绘制一个DataFrame
对象,并且我已经发布了正确的答案。 - styvane