- 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 - Line Chart
A pne shows a series of data points connected with a pne along the X-axis. It is an independent axis because the values on the X-axis do not depend on the vertical Y-axis.
The Y-axis is a dependent axis because its values depend on the X-axis and the result is the pne that progress horizontally.
Working with XlsxWriter Line Chart
To generate the pne chart programmatically using XlsxWriter, we use add_series(). The type of chart object is defined as pne .
Example
In the following example, we shall plot pne chart showing the sales figures of two products over six months. Two data series corresponding to sales figures of Product A and Product B are added to the chart with add_series() method.
import xlsxwriter wb = xlsxwriter.Workbook( hello.xlsx ) worksheet = wb.add_worksheet() headings = [ Month , Product A , Product B ] data = [ [ Jan , Feb , Mar , Apr , May , June ], [10, 40, 50, 20, 10, 50], [30, 60, 70, 50, 40, 30], ] bold=wb.add_format({ bold :True}) worksheet.write_row( A1 , headings, bold) worksheet.write_column( A2 , data[0]) worksheet.write_column( B2 , data[1]) worksheet.write_column( C2 , data[2]) chart1 = wb.add_chart({ type : pne }) chart1.add_series({ name : =Sheet1!$B$1 , categories : =Sheet1!$A$2:$A$7 , values : =Sheet1!$B$2:$B$7 , }) chart1.add_series({ name : [ Sheet1 , 0, 2], categories : [ Sheet1 , 1, 0, 6, 0], values : [ Sheet1 , 1, 2, 6, 2], }) chart1.set_title ({ name : Sales analysis }) chart1.set_x_axis({ name : Months }) chart1.set_y_axis({ name : Units }) worksheet.insert_chart( D2 , chart1) wb.close()
Output
After executing the above program, here is how XlsxWriter generates the Line chart −
Along with data_labels, the add_series() method also has a marker property. This is especially useful in a pne chart. The data points are indicated by marker symbols such as a circle, triangle, square, diamond etc. Let us assign circle and square symbols to the two data series in this chart.
chart1.add_series({ name : =Sheet1!$B$1 , categories : =Sheet1!$A$2:$A$7 , values : =Sheet1!$B$2:$B$7 , data_labels : { value : True}, marker : { type : circle }, }) chart1.add_series({ name : [ Sheet1 , 0, 2], categories : [ Sheet1 , 1, 0, 6, 0], values : [ Sheet1 , 1, 2, 6, 2], data_labels : { value : True}, marker : { type : square },})
The data labels and markers are added to the pne chart.
Line chart also supports stacked and percent_stacked subtypes.
Advertisements