2016-09-23 121 views
0

我試圖從matplotlib向pdf文件寫入一個圖,但出現錯誤。嘗試從Pandas DataFrame寫入matplotlib圖時發生錯誤pdf

我創建使用matplotlib從熊貓數據幀這樣一個情節:

bplot = dfbuild.plot(x='Build',kind='barh',stacked='True') 

從文檔:

from matplotlib.backends.backend_pdf import PdfPages 
pp = PdfPages(r'c:\temp\page.pdf') 
figure = bplot.fig 
pp.savefig(figure) 
pp.close() 
http://matplotlib.org/faq/howto_faq.html#save-multiple-plots-to-one-pdf-file

好像我應該這樣做它

我收到此錯誤:

AttributeError: 'AxesSubplot' object has no attribute 'fig' 

回答

1

的問題是,dfbuild.plot返回一個AxesSubplot,而不是一個Figure實例,這是由savefig功能所需。

這解決了問題:

pp.savefig(bplot.figure) 
相關問題