Python XlsxWriter Tutorial
Python XlsxWriter Useful Resources
Selected Reading
- Python XlsxWriter - VBA Macro
- Python XlsxWriter - Working with Pandas
- Python XlsxWriter - Cell Comments
- Python XlsxWriter - Header & Footer
- Python XlsxWriter - Page Setup
- Python XlsxWriter - Insert Image
- Python XlsxWriter - Textbox
- Python XlsxWriter - Hide/Protect Worksheet
- Python XlsxWriter - Freeze & Split Panes
- Python XlsxWriter - Outlines & Grouping
- Python XlsxWriter - Data Validation
- Python XlsxWriter - Sparklines
- Python XlsxWriter - Pie Chart
- Python XlsxWriter - Line Chart
- Python XlsxWriter - Bar Chart
- Python XlsxWriter - Chart Legends
- Python XlsxWriter - Chart Formatting
- Python XlsxWriter - Adding Charts
- Python XlsxWriter - Conditional Formatting
- Python XlsxWriter - Hyperlinks
- Python XlsxWriter - Border
- Python XlsxWriter - Number Formats
- Python XlsxWriter - Fonts & Colors
- Python XlsxWriter - Applying Filter
- Python XlsxWriter - Tables
- Python XlsxWriter - Date and Time
- Python XlsxWriter - Formula & Function
- Python XlsxWriter - Defined Names
- Python XlsxWriter - Cell Notation & Ranges
- Python XlsxWriter - Important classes
- Python XlsxWriter - Hello World
- Python XlsxWriter - Environment Setup
- Python XlsxWriter - Overview
- Python XlsxWriter - Home
Python XlsxWriter Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python XlsxWriter - Bar Chart
Python XlsxWriter - Bar Chart
The bar chart is similar to a column chart, except for the fact that the data is represented in proportionate horizontal bars instead of vertical columns. To produce a bar chart, the type argument of add_chart() method must be set to bar .
chart1 = workbook.add_chart({ type : bar })
The bar chart appears as follows −
There are two subtypes of bar chart, namely stacked and percent_stacked. In the stacked chart, the bars of different colors for a certain category are placed one after the other. In a percent_stacked chart, the length of each bar shows its percentage in the total value in each category.
chart1 = workbook.add_chart({ type : bar , subtype : percent_stacked })
Example
Program to generate percent stacked bar chart is given below −
import xlsxwriter wb = xlsxwriter.Workbook( hello.xlsx ) worksheet = wb.add_worksheet() chart1 = wb.add_chart({ type : bar , subtype : percent_stacked }) # Add the worksheet data that the charts will refer to. headings = [ Name , Phy , Maths ] data = [ ["Jay", 30, 60], ["Mohan", 40, 50], ["Veeru", 60, 70], ] worksheet.write_row(0,0, headings) worksheet.write_row(1,0, data[0]) worksheet.write_row(2,0, data[1]) worksheet.write_row(3,0, data[2]) chart1.add_series({ name : =Sheet1!$B$1 , categories : =Sheet1!$A$2:$A$4 , values : =Sheet1!$B$2:$B$4 , }) chart1.add_series({ name : [ Sheet1 , 0, 2], categories : [ Sheet1 , 1, 0, 3, 0], values : [ Sheet1 , 1, 2, 3, 2], }) chart1.set_title ({ name : Markpst , name_font : { name : Times New Roman , size :24}}) chart1.set_x_axis({ name : Students , name_font : { name : Arial , size :16, bold :True}, }) chart1.set_y_axis({ name : Marks , name_font : { name : Arial , size :16, bold :True}, num_font :{ name : Arial , itapc :True}}) chart1.set_legend({ position : bottom , font : { name : capbri , size : 9, bold : True}}) worksheet.insert_chart( B7 , chart1) wb.close()
Output
The output file will look pke the one given below −
Advertisements