如何使用python-pptx模块在Power Point中绘制带有标签和标题的特定折线图?

问题描述

我有一个像这样的数据集:

A       B       C       D
AR    20201     1     200
AR    20202     1     300
AR    20203     1     1000
AR    20204     1     3000
AR    20205     1     700
AR    20206     1     800
AR    20207     1     900

AR    20201     2    1000
AR    20202     2    2000
AR    20203     2    3000
AR    20204     2    4000
AR    20205     2    5676
AR    20206     2    6000
AR    20207     2    1000

AR    20201     3   4500
AR    20202     3   4567
AR    20203     3   1000
AR    20204     3   900
AR    20205     3   600
AR    20206     3   200
AR    20207     3  100

==========================
BR    20201     1
BR    20202     1
BR    20203     1
BR    20204     1
BR    20205     1
BR    20206     1
BR    20207     1

BR    20201     2
BR    20202     2
BR    20203     2
BR    20204     2
BR    20205     2
BR    20206     2
BR    20207     2

BR    20201     3
BR    20202     3
BR    20203     3
BR    20204     3
BR    20205     3
BR    20206     3
BR    20207     3

我正在使用循环在ppt中创建多重折线图。对于country ( Column A)=AR,我正在同一图上绘制不同C=1,2 and 3的折线图。在Y axis中,我将拥有column D;在X axis中,我将拥有column B

不同国家的军事机构。

我无法选择ppt中可用的特定折线图,该折线图还显示Y-DATA LABELS。另外,我的X轴格式不正确。如何将x标签倾斜45度对齐。

这是一个国家/地区的代码

chart_data = ChartData()
cat=['202001','202002','202003','202004','202005','202006','202007']
chart_data.categories = cat
        
for i in list(data["C"].unique()):
            
    chart_data.add_series(i,tuple(data[data['C']==i]['D']))
    x,y,cx,cy = Inches(1),Inches(1),Inches(10.5),Inches(6)
    chart = slide.shapes.add_chart(XL_CHART_TYPE.LINE,x,cy,chart_data).chart

    chart.has_legend = True
    chart.legend.include_in_layout = False
    chart.series[0].smooth = True

输出不是以上数据:

enter image description here

x轴间距不正确,并且Y标签也不在那里。我正在寻找的是他从ppt(Line with markers and annotations)中选取的线图:

enter image description here

如何更改以上代码来完成此操作?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)