Format Charts in Presentations Using Python
Overview
This article explains how to format charts in PowerPoint presentations by using Aspose.Slides. It shows how to customize key chart elements such as axes, grid lines, titles, legends, the plot area, and wall fills to improve the appearance and readability of chart data.
It also demonstrates how to set font properties for chart text, apply preset numeric formats to chart data, and enable rounded corners for the chart area. Together, these examples show how to control both the visual style and data presentation of charts in a presentation.
Format Chart Entities
Use Chart to format chart titles, axes, grid lines, legends, and the plot area. This example creates a line chart with markers and default data, then applies separate text and line styles to its value and category axes. Font sizes and line widths are specified in points; category labels are rotated by 45 degrees.
The value axis uses number_format independently of the source cells. Its scale runs from -2 to 15, with major intervals of 2 and minor intervals of 0.5. The example also combines percentage formatting with display_unit set to thousands, so adapt these settings to the meaning and magnitude of your data. The legend stays outside the plot area because overlay is disabled. Back-wall and floor fills are configured through back_wall and floor, but these surfaces are only visible in 3D charts.
import aspose.slides.charts as charts
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
chart = slide.shapes.add_chart(charts.ChartType.LINE_WITH_MARKERS, 50, 50, 500, 400)
chart.has_title = True
chart.chart_title.add_text_frame_for_overriding("")
chart_title = chart.chart_title.text_frame_for_overriding.paragraphs[0].portions[0]
chart_title.text = "Sample Chart"
chart_title.portion_format.fill_format.fill_type = slides.FillType.SOLID
chart_title.portion_format.fill_format.solid_fill_color.color = slides.Color.gray
chart_title.portion_format.font_height = 20
chart_title.portion_format.font_bold = slides.NullableBool.TRUE
chart_title.portion_format.font_italic = slides.NullableBool.TRUE
chart.axes.vertical_axis.major_grid_lines_format.line.fill_format.fill_type = slides.FillType.SOLID
chart.axes.vertical_axis.major_grid_lines_format.line.fill_format.solid_fill_color.color = slides.Color.blue
chart.axes.vertical_axis.major_grid_lines_format.line.width = 5
chart.axes.vertical_axis.major_grid_lines_format.line.dash_style = slides.LineDashStyle.DASH_DOT
chart.axes.vertical_axis.minor_grid_lines_format.line.fill_format.fill_type = slides.FillType.SOLID
chart.axes.vertical_axis.minor_grid_lines_format.line.fill_format.solid_fill_color.color = slides.Color.red
chart.axes.vertical_axis.minor_grid_lines_format.line.width = 3
chart.axes.vertical_axis.is_number_format_linked_to_source = False
chart.axes.vertical_axis.display_unit = charts.DisplayUnitType.THOUSANDS
chart.axes.vertical_axis.number_format = "0.0%"
chart.axes.vertical_axis.is_automatic_major_unit = False
chart.axes.vertical_axis.is_automatic_max_value = False
chart.axes.vertical_axis.is_automatic_minor_unit = False
chart.axes.vertical_axis.is_automatic_min_value = False
chart.axes.vertical_axis.max_value = 15
chart.axes.vertical_axis.min_value = -2
chart.axes.vertical_axis.minor_unit = 0.5
chart.axes.vertical_axis.major_unit = 2.0
vertical_axis_portion_format = chart.axes.vertical_axis.text_format.portion_format
vertical_axis_portion_format.font_bold = slides.NullableBool.TRUE
vertical_axis_portion_format.font_height = 16
vertical_axis_portion_format.font_italic = slides.NullableBool.TRUE
vertical_axis_portion_format.fill_format.fill_type = slides.FillType.SOLID
vertical_axis_portion_format.fill_format.solid_fill_color.color = slides.Color.dark_green
vertical_axis_portion_format.latin_font = slides.FontData("Times New Roman")
chart.axes.vertical_axis.has_title = True
chart.axes.vertical_axis.title.add_text_frame_for_overriding("")
vertical_axis_title = chart.axes.vertical_axis.title.text_frame_for_overriding.paragraphs[0].portions[0]
vertical_axis_title.text = "Primary Axis"
vertical_axis_title.portion_format.fill_format.fill_type = slides.FillType.SOLID
vertical_axis_title.portion_format.fill_format.solid_fill_color.color = slides.Color.gray
vertical_axis_title.portion_format.font_height = 20
vertical_axis_title.portion_format.font_bold = slides.NullableBool.TRUE
vertical_axis_title.portion_format.font_italic = slides.NullableBool.TRUE
chart.axes.horizontal_axis.major_grid_lines_format.line.fill_format.fill_type = slides.FillType.SOLID
chart.axes.horizontal_axis.major_grid_lines_format.line.fill_format.solid_fill_color.color = slides.Color.green
chart.axes.horizontal_axis.major_grid_lines_format.line.width = 5
chart.axes.horizontal_axis.minor_grid_lines_format.line.fill_format.fill_type = slides.FillType.SOLID
chart.axes.horizontal_axis.minor_grid_lines_format.line.fill_format.solid_fill_color.color = slides.Color.yellow
chart.axes.horizontal_axis.minor_grid_lines_format.line.width = 3
horizontal_axis_portion_format = chart.axes.horizontal_axis.text_format.portion_format
horizontal_axis_portion_format.font_bold = slides.NullableBool.TRUE
horizontal_axis_portion_format.font_height = 16
horizontal_axis_portion_format.font_italic = slides.NullableBool.TRUE
horizontal_axis_portion_format.fill_format.fill_type = slides.FillType.SOLID
horizontal_axis_portion_format.fill_format.solid_fill_color.color = slides.Color.blue
horizontal_axis_portion_format.latin_font = slides.FontData("Arial")
chart.axes.horizontal_axis.has_title = True
chart.axes.horizontal_axis.title.add_text_frame_for_overriding("")
horizontal_axis_title = chart.axes.horizontal_axis.title.text_frame_for_overriding.paragraphs[0].portions[0]
horizontal_axis_title.text = "Sample Category"
horizontal_axis_title.portion_format.fill_format.fill_type = slides.FillType.SOLID
horizontal_axis_title.portion_format.fill_format.solid_fill_color.color = slides.Color.gray
horizontal_axis_title.portion_format.font_height = 20
horizontal_axis_title.portion_format.font_bold = slides.NullableBool.TRUE
horizontal_axis_title.portion_format.font_italic = slides.NullableBool.TRUE
chart.axes.horizontal_axis.tick_label_position = charts.TickLabelPositionType.LOW
chart.axes.horizontal_axis.tick_label_rotation_angle = 45
legend_portion_format = chart.legend.text_format.portion_format
legend_portion_format.font_bold = slides.NullableBool.TRUE
legend_portion_format.font_height = 16
legend_portion_format.font_italic = slides.NullableBool.TRUE
legend_portion_format.fill_format.fill_type = slides.FillType.SOLID
legend_portion_format.fill_format.solid_fill_color.color = slides.Color.dark_red
chart.legend.overlay = False
chart.back_wall.thickness = 1
chart.back_wall.format.fill.fill_type = slides.FillType.SOLID
chart.back_wall.format.fill.solid_fill_color.color = slides.Color.orange
chart.floor.format.fill.fill_type = slides.FillType.SOLID
chart.floor.format.fill.solid_fill_color.color = slides.Color.red
chart.plot_area.format.fill.fill_type = slides.FillType.SOLID
chart.plot_area.format.fill.solid_fill_color.color = slides.Color.light_cyan
presentation.save("FormattedChart.pptx", slides.export.SaveFormat.PPTX)
Set Font Properties for a Chart
Set the default font size for chart text through Chart.text_format. The example creates a clustered column chart with a 20-point font and enables value labels for the first series through show_value. Text elements with their own explicit font settings can override the chart default.
import aspose.slides.charts as charts
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
chart = slide.shapes.add_chart(charts.ChartType.CLUSTERED_COLUMN, 100, 100, 500, 400)
chart.text_format.portion_format.font_height = 20
chart.chart_data.series[0].labels.default_data_label_format.show_value = True
presentation.save("ChartFontProperties.pptx", slides.export.SaveFormat.PPTX)
Set the Numeric Format
Use ChartDataCell.preset_number_format to apply a built-in number format to chart workbook cells. This example creates a clustered column chart with default, cell-backed data and applies format index 10 (0.00%) to each series value cell. This changes how the values are displayed in the workbook without changing the underlying numbers; for example, 0.25 is displayed as 25.00%. Axis and data-label formats can be configured separately.
import aspose.slides.charts as charts
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
chart = slide.shapes.add_chart(charts.ChartType.CLUSTERED_COLUMN, 50, 50, 500, 400)
for series in chart.chart_data.series:
for data_point in series.data_points:
data_point.value.as_cell.preset_number_format = 10 # 0.00%
presentation.save("PresetNumberFormat.pptx", slides.export.SaveFormat.PPTX)
The following table lists built-in number format indices with representative Excel formats for the English (United States) locale. The exact format strings and their display can vary by application and locale, particularly for currency and dates. Some Excel formats also differ from the defaults in the OOXML standard, as described in Microsoft’s number format implementation notes.
| Index | Format |
|---|---|
| 0 | General |
| 1 | 0 |
| 2 | 0.00 |
| 3 | #,##0 |
| 4 | #,##0.00 |
| 5 | "$"#,##0_);("$"#,##0) |
| 6 | "$"#,##0_);[Red]("$"#,##0) |
| 7 | "$"#,##0.00_);("$"#,##0.00) |
| 8 | "$"#,##0.00_);[Red]("$"#,##0.00) |
| 9 | 0% |
| 10 | 0.00% |
| 11 | 0.00E+00 |
| 12 | # ?/? |
| 13 | # ??/?? |
| 14 | m/d/yyyy |
| 15 | d-mmm-yy |
| 16 | d-mmm |
| 17 | mmm-yy |
| 18 | h:mm AM/PM |
| 19 | h:mm:ss AM/PM |
| 20 | h:mm |
| 21 | h:mm:ss |
| 22 | m/d/yyyy h:mm |
| 37 | #,##0_);(#,##0) |
| 38 | #,##0_);[Red](#,##0) |
| 39 | #,##0.00_);(#,##0.00) |
| 40 | #,##0.00_);[Red](#,##0.00) |
| 41 | _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_) |
| 42 | _("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_) |
| 43 | _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_) |
| 44 | _("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_) |
| 45 | mm:ss |
| 46 | [h]:mm:ss |
| 47 | mm:ss.0 |
| 48 | ##0.0E+0 |
| 49 | @ |
Set Chart Area Rounded Borders
Enable Chart.has_rounded_corners to round the corners of the chart area. The example creates a clustered column chart and uses line_format to give its outline a solid gray color and a single-line style before saving the presentation.
import aspose.slides.charts as charts
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
chart = slide.shapes.add_chart(charts.ChartType.CLUSTERED_COLUMN, 20, 100, 600, 400)
chart.line_format.fill_format.fill_type = slides.FillType.SOLID
chart.line_format.fill_format.solid_fill_color.color = slides.Color.gray
chart.line_format.style = slides.LineStyle.SINGLE
chart.has_rounded_corners = True
presentation.save("RoundedBorders.pptx", slides.export.SaveFormat.PPTX)
Edit Existing Chart Annotations
A chart can contain custom shapes, such as a text annotation explaining the status of a report. Access these shapes through Chart.user_shapes. Its shapes collection contains the chart-owned shapes.
An ordinary text box placed over a chart belongs to the slide, even if it looks like part of the chart. Iterating through Slide.shapes finds the chart and ordinary slide shapes, but does not enumerate the individual shapes inside the chart. Chart titles and data labels are separate chart elements, not custom annotations in this collection.
Download chart-annotations.pptx and place it in the application’s working directory. Its first slide contains a chart with an ungrouped annotation reading “Preliminary results”, a chart-owned line, and an ordinary slide text box reading “Slide overlay”. The example finds the first chart on that slide and changes the annotation to “Final results” when the report is ready to publish. It checks for an empty collection and only edits an AutoShape with a text_frame that is not None and contains the expected text.
import aspose.slides as slides
import aspose.slides.charts as charts
with slides.Presentation("chart-annotations.pptx") as presentation:
slide = presentation.slides[0]
chart = next((shape for shape in slide.shapes if isinstance(shape, charts.Chart)), None)
if chart is None or len(chart.user_shapes.shapes) == 0:
print("No chart or chart-owned shapes found.")
else:
updated = False
for shape in chart.user_shapes.shapes:
if isinstance(shape, slides.AutoShape) and shape.text_frame is not None:
if shape.text_frame.text == "Preliminary results":
shape.text_frame.text = "Final results"
updated = True
break
if updated:
presentation.save("chart-annotations-updated.pptx", slides.export.SaveFormat.PPTX)
else:
print("No matching text annotation found.")
The line and the slide text box remain unchanged. The following images show the input and the saved, reopened result:
| Before editing | After editing |
|---|---|
![]() |
![]() |
Note
The example inspects only the top-level chart-owned shapes. If an annotation is inside a GroupShape, inspect that group’s shapes collection as well. Repeat this recursively for nested groups, applying the same text checks to their child shapes. A group itself is a container; do not treat it as a text box.FAQ
Can I set semi-transparent fills for columns/areas while keeping the border opaque?
Yes. Fill transparency and the outline are configured separately. This is useful for improving the readability of the grid and data in dense visualizations.
How can I deal with data labels when they overlap?
Reduce the font size, disable nonessential label components (for example, categories), adjust the label position, show labels only for selected points if necessary, or switch the format to “value + legend”.
Can I apply gradient or pattern fills to series?
Yes. Series support solid, gradient, and pattern fills. In practice, use gradients sparingly and avoid combinations that reduce contrast with the grid and text.

