我正在对折线图上跨越一年的时间序列数据进行建模。我将类别轴标签作为日期,但它会自动在x轴上显示12个标签(日期)。我想将其更改为显示3个或4个标签。
在powerpoint本身上,此功能将位于“格式轴”->“轴选项”->“标签”->下,然后将“标签之间的间隔”从自动更改为“指定间隔单位”。我不知道如何在代码中执行此操作。
此外,了解如何将类别轴设置为日期轴将很有帮助。
def add_stock_chart(ppt,data, company, slide_num =0):
# data is a series indexed by date -- dates are all written as 'Excel numbers'
# company_name is a string of the company's ticker
slide = ppt.slides[slide_num]
chart_data = CategoryChartData()
chart_data.categories = data.index.tolist()
chart_data.add_series(str(company),tuple(data.values.tolist()))
x, y, cx, cy = Inches(.403), Inches(5.33), Inches(2.22), Inches(1.3)
chart = slide.shapes.add_chart(
XL_CHART_TYPE.LINE, x, y, cx, cy, chart_data
).chart
chart.font.size = Pt(8)
chart.font.name = 'Arial'
date_axis = chart.category_axis
date_axis.tick_labels.number_format = 'mmm-yy'
date_axis.major_unit = 90
chart.has_legend = False
chart.show_legend_key = False
chart.has_title = False
chart.series[0].smooth = True
return ppt