简体   繁体   English

python pptx库的堆叠列

[英]stacked columns with pptx library of python

How can I make the columns of the chart stacked when I build a .pptx report with pptx library of python? 使用python的pptx库构建.pptx报表时,如何使图表的列堆叠?

This is an example of the output that I need: 这是我需要的输出示例:

Thank you in advance 先感谢您

In fact I found the solution using : XL_CHART_TYPE.COLUMN_STACKED 实际上,我使用以下方法找到了解决方案: XL_CHART_TYPE.COLUMN_STACKED

This is the Output: [enter image description here][1] 这是输出:[在此处输入图像描述] [1]

This is an code: 这是一个代码:

from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches
# create presentation with 1 slide ------
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])
# define chart data ---------------------
chart_data = CategoryChartData()
chart_data.categories = ['East', 'West', 'Midwest']
chart_data.add_series('Series 1', (19.2, 21.4, 16.7))
chart_data.add_series('Series 2', (19.2, 21.4, 16.7))
chart_data.add_series('Series 3', (19.2, 21.4, 16.7))
# add chart to slide --------------------
x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_STACKED, x, y, cx, cy, chart_data
)
prs.save('chart-01.pptx')


  [1]: https://i.stack.imgur.com/JdDz1.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM