问题
I have a dataset which looks like this:
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
I am using loop to create multile line charts in ppt. For country ( Column A)=AR
I am plotting line charts for different C=1,2 and 3
on same plot. In the Y axis
I will have column D
and on X axis
I will have column B
Similary for different country.
I am not able to choose particular line graph available in ppt which also shows Y-DATA LABELS
. Also my X-axis is not properly formatted. How to align x labels 45 degree slanting.
Here is the code for one country:
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, y, cx, cy, chart_data).chart
chart.has_legend = True
chart.legend.include_in_layout = False
chart.series[0].smooth = True
Output is not of above data:
The x-axis is not properly spaced and also Y-labels is not there. What I am looking is his line plot which I picked from ppt ( Line with markers and annotations
):
How can I change the above code to accomplish this?
来源:https://stackoverflow.com/questions/64162259/how-to-plot-particular-line-chart-with-labels-and-titles-in-power-point-using-py