How to change the legend font size using xlsxwriter - python

Refresh

November 2018

Views

1.4k time

3

How to change the legend font size using 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 answers

1

Это в настоящее время невозможно изменить шрифт в XlsxWriter графики легенд.

Если добавить его как запрос функции на GitHub я попытаюсь обойти ее.

Обновление : Добавлено в версии 0.4.6 от XlsxWriter .