Skip to content Skip to sidebar Skip to footer

Read Chart Data From Existing Chart Using Python-pptx

I'd like to use the python-pptx library to read data from charts inside a presentation. I've seen the documentation to replace chart data, but I can't figure out how to read data.

Solution 1:

Chart data is:

  • the chart's chart-type
  • its category names (and possibly hierarchical organization)
  • its series names
  • and its series values

These are available at the plot level, for example:

>>> chart.chart_type
DOUGHNUT
>>> plot = chart.plots[0]
>>> category_labels = [c.label for c in plot.categories]
["West", "North", "South"]
>>> series = plot.series[0]
>>> series.name
'Sales'
>>> series.values
(17.8, 24.5, 88.0)

There are subtleties depending on the chart/plot type. Consult the API document here to learn more about those. https://python-pptx.readthedocs.io/en/latest/api/chart.html


Post a Comment for "Read Chart Data From Existing Chart Using Python-pptx"