【问题标题】:How to change the legend font size using xlsxwriter - python如何使用 xlsxwriter - python 更改图例字体大小
【发布时间】:2013-10-22 07:54:54
【问题描述】:

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

【问题讨论】:

    标签: python excel font-size legend xlsxwriter


    【解决方案1】:

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

    如果您将其作为功能请求添加到 GitHub,我会尝试解决它。​​

    更新:添加于version 0.4.6 of XlsxWriter

    【讨论】:

    • 非常感谢@jmcnamara!这是一个伟大的项目!我添加了一个功能请求!再次感谢您!
    猜你喜欢
    • 2023-01-16
    • 2016-08-18
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    相关资源
    最近更新 更多