如何使用xlsxwriter更改图例字体大小 - python

时间:2013-10-14 17:09:21

标签: python excel font-size legend xlsxwriter

如何使用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()

1 个答案:

答案 0 :(得分:1)

目前无法更改XlsxWriter图表图例中的字体。

如果您将其添加为GitHub上的功能请求,我会尝试解决此问题。

更新:已添加到version 0.4.6 of XlsxWriter