Python Plotting Pie Chart To Microsoft Excel

In this article i want to show you Plotting Pie Chart To Microsoft Excel with Python, we are going to use XlsxWriter library for this purpose. XlsxWriter is a Python module for writing files in the Excel 2007+ XLSX file format. XlsxWriter can be used to write text, numbers, formulas and hyperlinks to multiple worksheets and it supports features such as formatting and many more, including:

  • 100% compatible Excel XLSX files.
  • Full formatting.
  • Merged cells.
  • Defined names.
  • Charts.
  • Autofilters.
  • Data validation and drop down lists.
  • Conditional formatting.
  • Worksheet PNG/JPEG/BMP/WMF/EMF images.
  • Rich multi-format strings.
  • Cell comments.
  • Integration with Pandas.
  • Textboxes.
  • Support for adding Macros.
  • Memory optimization mode for writing large files.

It supports Python 2.7, 3.4+ and PyPy and uses standard libraries only.

 

For plotting the charts on an excel sheet, firstly, create chart object of specific chart type( i.e Pie chart etc.). After creating chart objects, insert data in it and lastly, add that chart object in the sheet object. also for plotting the simple Pie chart on an excel sheet, use add_chart() method with type ‘pie’ keyword argument of a workbook object.

 

First of all you need to install the library

 

 

So now this is the complete code

 

Run the complete code and this will be the result

 

Python Plotting Pie Chart To Microsoft Excel
Python Plotting Pie Chart To Microsoft Excel

 

 

 

Also you can watch the complete video for this article

 

1 thought on “Python Plotting Pie Chart To Microsoft Excel”

  1. If we have data in multiple sheets.. Ex: Sheet 1 has a data and sheet 2 has another data in this case when we want append and plot the pie chart with % and original value like 80%, 80.. in their respective sheets. How can we achieve this?

Comments are closed.

Share via
Copy link
Powered by Social Snap