Collections for Plotting

Collections are a number of different symbols that can be plotted as a unit in matplotlib, which is very handy when plotting a large number of the same component, such as junctions in pandapipes. In order to create such collections for different components of a pandapipes network, there are some functions to be found in the plotting module of pandapipes.

Creating Collections

The following functions can be used to create collections for the most important components of a pandapipes network. Please note that some of these functions in fact return more than just one collection:

create_junction_collection(net, junctions=None, size=5, patch_type='circle', color=None, z=None, cmap=None, norm=None, infofunc=None, picker=False, junction_geodata=None, cbar_title='Junction Pressure [bar]', **kwargs)

Creates a matplotlib patch collection of pandapipes junctions.

Parameters
  • net (pandapipesNet) – The pandapipes network

  • junctions (list, default None) – The junctions for which the collections are created. If None, all junctions in the network are considered.

  • size (int, default 5) – Patch size

  • patch_type (str, default "circle") –

    Patch type, can be

    • ”circle” or “ellipse” for an ellipse (cirlces are just ellipses with the same width + height)

    • ”rect” or “rectangle” for a rectangle

    • ”poly<n>” for a polygon with n edges

  • color (iterable, float, default None) – Color or list of colors for every element

  • z (array, default None) – Array of magnitudes for colormap. Used in case of given cmap. If None, net.res_junction.p_bar is used.

  • cmap (matplotlib colormap object, default None) – colormap for the patch colors

  • norm (matplotlib norm object, default None) – matplotlib norm object

  • infofunc (function, default None) – infofunction for the patch element

  • picker (bool, default False) – Picker argument passed to the patch collection

  • junction_geodata (pandas.DataFrame, default None) – Coordinates to use for plotting. If None, net[“junction_geodata”] is used

  • cbar_title (str, default "Junction Pressure [bar]") – colormap bar title in case of given cmap

  • kwargs – Keyword arguments are passed to the patch function and the patch maker

Returns

pc (matplotlib collection object) - patch collection

create_pipe_collection(net, pipes=None, pipe_geodata=None, junction_geodata=None, use_junction_geodata=False, infofunc=None, cmap=None, norm=None, picker=False, z=None, cbar_title='Pipe Loading [%]', clim=None, **kwargs)

Creates a matplotlib pipe collection of pandapipes pipes.

Parameters
  • net (pandapipesNet) – The pandapipes network

  • pipes (list, default None) – The pipes for which the collections are created. If None, all pipes in the network are considered.

  • pipe_geodata (pandas.DataFrame, default None) – Coordinates to use for plotting. If None, net[“pipe_geodata”] is used.

  • junction_geodata (pandas.DataFrame, default None) – Coordinates to use for plotting in case of use_junction_geodata = True. If None, net[“junction_geodata”] is used.

  • use_junction_geodata (bool, default False) – Defines whether junction or pipe geodata are used.

  • infofunc (function, default None) – infofunction for the line element

  • cmap (matplotlib norm object, default None) – colormap for the line colors

  • norm (matplotlib norm object, default None) – matplotlib norm object

  • picker (bool, default False) – Picker argument passed to the patch collection

  • z (array, default None) – Array of pipe loading magnitudes for colormap. Used in case of given cmap. If None, net.res_pipe.loading_percent is used.

  • cbar_title (str, default "Pipe Loading [%]") – colormap bar title in case of given cmap

  • clim (tuple of floats, default None) – Setting the norm limits for image scaling

  • kwargs – Keyword arguments are passed to the patch function and the patch maker

Returns

lc (matplotlib line collection) - line collection for pipes

create_sink_collection(net, sinks=None, size=1.0, infofunc=None, picker=False, orientation=2.6179938779914944, **kwargs)

Creates a matplotlib patch collection of pandapipes sinks.

Parameters
  • net (pandapipesNet) – The pandapipes network

  • sinks (list, default None) – The sinks for which the collections are created. If None, all sinks connected to junctions that have junction_geodata entries are considered.

  • size (float, default 1) – Patch size

  • infofunc (function, default None) – infofunction for the patch element

  • picker (bool, default False) – Picker argument passed to the patch collection

  • orientation (float, default np.pi*(5/6)) – Orientation of sink collection. pi is directed downwards, increasing values lead to clockwise direction changes.

  • kwargs – Keyword arguments are passed to the patch function

Returns

sink_pc - patch collection, sink_lc - line collection

create_source_collection(net, sources=None, size=1.0, infofunc=None, picker=False, orientation=3.665191429188092, **kwargs)

Creates a matplotlib patch collection of pandapipes sources.

Parameters
  • net (pandapipesNet) – The pandapipes network

  • sources (list, default None) – The sources for which the collections are created. If None, all sources connected to junctions that have junction_geodata entries are considered.

  • size (float, default 1.) – Patch size

  • infofunc (function, default None) – infofunction for the patch element

  • picker (bool, default False) – Picker argument passed to the patch collection

  • orientation (float, default np.pi*(7/6)) – Orientation of source collection. pi is directed downwards, increasing values lead to clockwise direction changes.

  • kwargs – Keyword arguments are passed to the patch function

Returns

source_pc - patch collection, source_lc - line collection

create_ext_grid_collection(net, size=1.0, infofunc=None, orientation=0, picker=False, ext_grids=None, ext_grid_junctions=None, **kwargs)

Creates a matplotlib patch collection of pandapipes ext_grid. Parameters ext_grids, ext_grid_junctions can be used to specify, which ext_grids the collection should be created for.

Parameters
  • net (pandapipesNet) – The pandapipes network

  • size (float, default 1.) – Patch size

  • infofunc (function, default None) – infofunction for the patch element

  • orientation (float, default 0) – Orientation of ext_grid collection. 0 is directed upwards, increasing values lead to clockwise direction changes.

  • picker (bool, default False) – Picker argument passed to the patch collection

  • ext_grids (list, default None) – The ext_grids for which the collections are created. If None, all ext_grids which have the entry coords in ext_grid_geodata are considered.

  • ext_grid_junctions (np.ndarray, default None) – Junctions to be used as ext_grid locations

  • kwargs – Keyword arguments are passed to the patch function

Returns

ext_grid1 - patch collection, ext_grid2 - patch collection

create_valve_collection(net, valves=None, size=5.0, junction_geodata=None, color='k', infofunc=None, picker=False, fill_closed=True, respect_valves=False, **kwargs)

Creates a matplotlib patch collection of pandapipes junction-junction valves. Valves are plotted in the center between two junctions with a “helper” line (dashed and thin) being drawn between the junctions as well.

Parameters
  • net (pandapipesNet) – The pandapipes network

  • valves (list, default None) – The valves for which the collections are created. If None, all valves which have entries in the respective junction geodata will be plotted.

  • size (float, default 5.) – Patch size

  • junction_geodata (pandas.DataFrame, default None) – Coordinates to use for plotting. If None, net[“junction_geodata”] is used.

  • colors (iterable, float, default None) – Color or list of colors for every valve

  • infofunc (function, default None) – infofunction for the patch element

  • picker (bool, default False) – Picker argument passed to the patch collection

  • fill_closed (bool, default True) – If True, valves with parameter opened == False will be filled and those with opened == True will have a white facecolor. Vice versa if False.

  • kwargs – Keyword arguments are passed to the patch function

Returns

lc - line collection, pc - patch collection

create_heat_exchanger_collection(net, heat_ex=None, size=5.0, junction_geodata=None, color='k', infofunc=None, picker=False, **kwargs)

Creates a matplotlib patch collection of pandapipes junction-junction heat_exchangers. Heat_exchangers are plotted in the center between two junctions with a “helper” line (dashed and thin) being drawn between the junctions as well.

Parameters
  • net (pandapipesNet) – The pandapipes network

  • size (float, default 2.) – Patch size

  • helper_line_style (str, default ":") – Line style of the “helper” line being plotted between two junctions connected by a junction-junction heat_exchanger

  • helper_line_size (float, default 1.) – Line width of the “helper” line being plotted between two junctions connected by a junction-junction heat_exchanger

  • helper_line_color (str, default "gray") – Line color of the “helper” line being plotted between two junctions connected by a junction-junction valve

  • orientation (float, default np.pi/2) – Orientation of heat_exchanger collection. pi is directed downwards, increasing values lead to clockwise direction changes.

  • kwargs – Keyword arguments are passed to the patch function

Returns

heat_exchanger, helper_lines

Return type

tuple of patch collections

Drawing Collections

In order to draw a number of created collections, they can be added to a list and handed over to the function draw_collections() which is actually part of pandapower. It returns a matplotlib axes, which can be extended by using add_collections_to_axes().

draw_collections(collections, figsize=(10, 8), ax=None, plot_colorbars=True, set_aspect=True, axes_visible=(False, False), copy_collections=True, draw=True)

Draws matplotlib collections which can be created with the create collection functions.

Input:

collections (list) - iterable of collection objects, may include tuples of collections

OPTIONAL:

figsize (tuple, (10,8)) - figsize of the matplotlib figure

ax (axis, None) - matplotlib axis object to plot into, new axis is created if None

plot_colorbars (bool, True) - defines whether colorbars should be plotted

set_aspect (bool, True) - defines whether ‘equal’ and ‘datalim’ aspects of axis scaling should be set.

axes_visible (tuple, (False, False)) - defines visibility of (xaxis, yaxis)

OUTPUT:

ax - matplotlib axes

add_collections_to_axes(ax, collections, plot_colorbars=True, copy_collections=True)