Charts visualize data in PowerPoint presentations. python-pptx supports most PowerPoint chart types including column, bar, line, pie, XY (scatter), and bubble charts.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/scanny/python-pptx/llms.txt
Use this file to discover all available pages before exploring further.
Adding a chart
Create charts using chart data objects and theadd_chart() method:
add_chart() returns a GraphicFrame shape containing the chart. Access the chart via the chart property.Category charts
Category charts use discrete categories for the X-axis (column, bar, line, pie, etc.).Single series chart
Multi-series chart
Chart types
- Column chart
- Bar chart
- Line chart
- Pie chart
XY and bubble charts
XY (scatter) charts use continuous values for both axes. Bubble charts add a third dimension via marker size.XY scatter chart
Bubble chart
Formatting charts
Axes
Customize category and value axes:Data labels
Add and format data labels:Legend
Add and position a legend:XL_LEGEND_POSITION.BOTTOMXL_LEGEND_POSITION.LEFTXL_LEGEND_POSITION.RIGHTXL_LEGEND_POSITION.TOPXL_LEGEND_POSITION.CORNER
Complete examples
Understanding plots
A plot (called ChartGroup in the Microsoft API) is a sub-chart containing one or more series. Most charts have a single plot, but combination charts can have multiple plots.Working with series
Access and customize individual series:Chart colors
By default, charts use theme colors (Accent 1 through Accent 6). To customize colors:- Use theme colors: Modify the theme colors in your template presentation
- Set data point colors: Customize individual data points programmatically (support varies by chart type)
Best practices
- Use
CategoryChartDatafor column, bar, line, and pie charts - Use
XyChartDatafor scatter charts - Use
BubbleChartDatafor bubble charts - Set
include_in_layout = Falsefor legends to prevent chart resizing - Format tick labels with appropriate number formats (
'0%','$#,##0', etc.) - Enable gridlines for easier data reading
- Keep legends concise and position them appropriately
- Use consistent chart dimensions across slides for professional appearance