To set the position of the horizontal axis title in a chart using xlwings in Python, you can use the following code:

import xlwings as xw

# Connect to Excel
app = xw.App(visible=False)
wb = xw.Book('your_workbook.xlsx')
sheet = wb.sheets['your_sheet']

# Set the position of the horizontal axis title
chart = sheet.charts['your_chart']
chart.api.Axes(1).HasTitle = True
chart.api.Axes(1).AxisTitle.Left = 100
chart.api.Axes(1).AxisTitle.Top = 50

# Save and close the workbook
wb.save()
wb.close()

In the code above, you need to replace 'your_workbook.xlsx', 'your_sheet', and 'your_chart' with the actual names of your workbook, sheet, and chart, respectively.

The chart.api.Axes(1) refers to the horizontal axis of the chart. By setting HasTitle = True, you enable the axis title. Then, you can use AxisTitle.Left and AxisTitle.Top to set the position of the axis title. The units are in points, where 72 points equal 1 inch.

Finally, you need to save and close the workbook.

Note: Make sure you have the xlwings library installed and imported correctly before running this code

python xlwings chart 横轴标题名称位置设置chartapi1Axes1

原文地址: https://www.cveoy.top/t/topic/iJtu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录