2014-07-23 120 views
7

我使用python 3.4,pandas 0.14.1和XlsxWriter 0.5.6。 創建用下面的代碼使用XlsxWriter將熊貓圖表插入Excel文件

graph=data_iter['_DiffPrice'].hist() 

,其產生的美麗直方圖使用大熊貓稱爲「圖形」的曲線圖。

現在,我該如何使用XlsxWriter將該圖插入到Excel文件中?

我試過XlsxWriter方法

workbook.add_chart() 

但在Excel中創建一個圖表,不是我想要的。

感謝

+1

pandas使用matplotlib進行繪圖。 [這個答案](http://stackoverflow.com/a/15177991/2948808)應該會對你有所幫助。 – RJT

+0

是的,這有幫助。因此,策略是首先將圖形保存在磁盤上,然後將其作爲圖像粘貼到Excel文件中。有效。謝謝RJT。 – Charles

回答

13

如果您想使用XlsxWriter然後看看下面如何做(我寫)出口熊貓數據的圖表在Excel中:Using Pandas and XlsxWriter to create Excel charts

enter image description here

如果另一方面要通過熊貓產生的matplotlib風格圖表,然後將其導出爲圖像,並用XlsxWriter insert_image()方法將它們插入到工作表。請參閱Working with Python Pandas and XlsxWriter

+0

謝謝!在我的情況下,第二個策略(導出,然後粘貼'insert_image()')是我需要的。但很高興知道有另一種方法。 – Charles