pandas 使用 XlsxWriter 将熊猫图表插入到 Excel 文件中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24907210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert pandas chart into an Excel file using XlsxWriter
提问by Charles
I use python 3.4, pandas 0.14.1 and XlsxWriter 0.5.6. I create a graph called 'graph' using pandas with the following code
我使用 python 3.4、pandas 0.14.1 和 XlsxWriter 0.5.6。我使用以下代码使用Pandas创建了一个名为“graph”的图形
graph=data_iter['_DiffPrice'].hist()
, which produces a beautiful histogram.
,这会产生一个漂亮的直方图。
Now, how do I insert that graph into an Excel file using XlsxWriter?
现在,如何使用 XlsxWriter 将该图形插入 Excel 文件中?
I tried the XlsxWriter method
我尝试了 XlsxWriter 方法
workbook.add_chart()
but this creates a graph in Excel, not what I want.
但这会在 Excel 中创建一个图表,而不是我想要的。
Thanks
谢谢
回答by jmcnamara
If you would like to export Pandas data as charts in Excel using XlsxWriter then have a look at the following how-to (that I wrote): Using Pandas and XlsxWriter to create Excel charts.
如果您想使用 XlsxWriter 在 Excel 中将 Pandas 数据导出为图表,请查看以下操作方法(我编写的):使用 Pandas 和 XlsxWriter 创建 Excel 图表。


If on the other hand you want the matplotlib style charts generated by Pandas then export them as images and insert them into a worksheet using the XlsxWriter insert_image()method.
另一方面,如果您想要 Pandas 生成的 matplotlib 样式图表,则将它们导出为图像并使用 XlsxWriterinsert_image()方法将它们插入到工作表中。

