如何使用 xlsxwriter 更改图例字体大小:
import xlsxwriter
workbook = xlsxwriter.Workbook('chart_pie.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
# Add the worksheet data that the charts will refer to.
headings = ['Category', 'Values']
data = [
['Apple', 'Cherry', 'Pecan'],
[60, 30, 10],
]
worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
#######################################################################
#
# Create a new chart object.
#
chart1 = workbook.add_chart({'type': 'pie'})
# Configure the series. Note the use of the list syntax to define ranges:
# List is [ sheet_name, first_row, first_col, last_row, last_col ].
chart1.add_series({
'name': 'Pie sales data',
'categories': ['Sheet1', 1, 0, 3, 0],
'values': ['Sheet1', 1, 1, 3, 1],
})
# Add a title.
chart1.set_title({'name': 'Popular Pie Types'})
# Set an Excel chart style. Colors with white outline and shadow.
chart1.set_style(10)
# Insert the chart into the worksheet (with an offset).
worksheet.insert_chart('C2', chart1, {'x_offset': 25, 'y_offset': 10})
workbook.close()