larray.ReportSheet.add_graph

ReportSheet.add_graph(data, title=None, template=None, width=None, height=None, min_y=None, max_y=None, xticks_spacing=None, customize_func=None, customize_kwargs=None)[source]

Add a graph item to the current sheet.

Note that the current method only add a new item to the list of items to be generated. The report Excel file is generated only when the to_excel is called.

Parameters
data1D or 2D array-like

1D or 2D array representing the data associated with the graph. The first row represents the abscissa labels. Each additional row represents a new series and must start with the name of the current series.

titlestr, optional

title of the graph. Defaults to None.

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.

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_be = report.new_sheet('Belgium')

Specifying the ‘template’

>>> sheet_be.add_graph(demo.population['Belgium'], 'Population', template='Line')

Specifying the ‘template’, ‘width’ and ‘height’ values

>>> sheet_be.add_graph(demo.births['Belgium'], 'Births', template='Line', width=450, height=250)

Setting a default template

>>> sheet_be.template = 'Line_Marker'
>>> sheet_be.add_graph(demo.deaths['Belgium'], 'Deaths')

Specify the mininum and maximum values for the Y axis

>>> sheet_be.add_graph(demo.population['Belgium'],
...                    'Population (min/max Y axis = 5/6 millions)',
...                     min_y=5e6, max_y=6e6)

Specify the interval between two ticks (X axis)

>>> sheet_be.add_graph(demo.population['Belgium'], 'Population (every 2 years)', xticks_spacing=2)

Dumping the report Excel file

>>> # do not forget to call 'to_excel' to create the report file
>>> report.to_excel('Demography_Report.xlsx')