larray.ReportSheet.add_graphs

ReportSheet.add_graphs(array_per_title, axis_per_loop_variable, template=None, width=None, height=None, graphs_per_row=1, min_y=None, max_y=None, xticks_spacing=None, customize_func=None, customize_kwargs=None)[source]

Add multiple graph items to the current sheet.

This method is mainly useful when multiple graphs are generated by iterating over one or several axes of an array (see examples below). The report Excel file is generated only when the to_excel is called.

Parameters
array_per_title: dict

dictionary containing pairs (title template, array).

axis_per_loop_variable: dict

dictionary containing pairs (variable used in the title template, axis).

templatestr or Path, optional

name of the template to be used to generate the graph. The full path to the template file must be provided if no template directory has not been set or if the template file belongs to another directory. Defaults to the defined template (see set_graph_template).

widthint, optional

width of the title item. The current default value is used if None (see set_item_default_size). Defaults to None.

heightint, optional

height of the title item. The current default value is used if None (see set_item_default_size). Defaults to None.

graphs_per_row: int, optional

Number of graphs per row. Defaults to 1.

min_y: int, optional

minimum value for the Y axis.

max_y: int, optional

maximum value for the Y axis.

xticks_spacing: int, optional

space interval between two ticks along the X axis.

customize_func: function, optional

user defined function to personalize the graph. The function must take the Chart object as first argument. All keyword arguments defined in customize_kwargs are passed to the function at call.

customize_kwargs: dict, optional

keywords arguments passed to the function customize_func at call.

Examples

>>> demo = load_example_data('demography_eurostat')
>>> report = ExcelReport(EXAMPLE_EXCEL_TEMPLATES_DIR)
>>> sheet_population = report.new_sheet('Population')
>>> population = demo.population

Generate a new graph for each combination of gender and year

>>> sheet_population.add_graphs(
...     {'Population of {gender} by country in {year}': population},
...     {'gender': population.gender, 'year': population.time},
...     template='line', width=450, height=250, graphs_per_row=2)

Specify the mininum and maximum values for the Y axis

>>> sheet_population.add_graphs({'Population of {gender} by country for the year {year}': population},
...                      {'gender': population.gender, 'year': population.time},
...                      template='line', width=450, height=250, graphs_per_row=2, min_y=0, max_y=50e6)

Specify the interval between two ticks (X axis)

>>> sheet_population.add_graphs({'Population of {gender} by country for the year {year}': population},
...                      {'gender': population.gender, 'year': population.time},
...                      template='line', width=450, height=250, graphs_per_row=2, xticks_spacing=2)
>>> # do not forget to call 'to_excel' to create the report file
>>> report.to_excel('Demography_Report.xlsx')