edisgo.tools.plots

Module Contents

Functions

histogram(data, **kwargs)

Function to create histogram, e.g. for voltages or currents.

add_basemap(ax[, zoom])

Adds map to a plot.

get_grid_district_polygon(config[, subst_id, projection])

Get MV network district polygon from oedb for plotting.

mv_grid_topology(edisgo_obj[, timestep, line_color, ...])

Plot line loading as color on lines.

color_map_color(→ str)

Get matching color for a value on a matplotlib color map.

plot_plotly(→ plotly.basedatatypes.BaseFigure)

Draws a plotly html figure.

chosen_graph(→ tuple[networkx.Graph, ...)

Get the matching networkx graph from a chosen grid.

plot_dash_app(→ jupyter_dash.JupyterDash)

Generates a jupyter dash app from given eDisGo object(s).

plot_dash(edisgo_objects[, mode, debug, port, height])

Shows the generated jupyter dash app from given eDisGo object(s).

edisgo.tools.plots.histogram(data, **kwargs)[source]

Function to create histogram, e.g. for voltages or currents.

Parameters:
  • data (pandas.DataFrame) – Data to be plotted, e.g. voltage or current (v_res or i_res from network.results.Results). Index of the dataframe must be a pandas.DatetimeIndex.

  • timeindex (pandas.Timestamp or list(pandas.Timestamp) or None, optional) – Specifies time steps histogram is plotted for. If timeindex is None all time steps provided in data are used. Default: None.

  • directory (str or None, optional) – Path to directory the plot is saved to. Is created if it does not exist. Default: None.

  • filename (str or None, optional) – Filename the plot is saved as. File format is specified by ending. If filename is None, the plot is shown. Default: None.

  • color (str or None, optional) – Color used in plot. If None it defaults to blue. Default: None.

  • alpha (float, optional) – Transparency of the plot. Must be a number between 0 and 1, where 0 is see through and 1 is opaque. Default: 1.

  • title (str or None, optional) – Plot title. Default: None.

  • x_label (str, optional) – Label for x-axis. Default: “”.

  • y_label (str, optional) – Label for y-axis. Default: “”.

  • normed (bool, optional) – Defines if histogram is normed. Default: False.

  • x_limits (tuple or None, optional) – Tuple with x-axis limits. First entry is the minimum and second entry the maximum value. Default: None.

  • y_limits (tuple or None, optional) – Tuple with y-axis limits. First entry is the minimum and second entry the maximum value. Default: None.

  • fig_size (str or tuple, optional) –

    Size of the figure in inches or a string with the following options:
    • ’a4portrait’

    • ’a4landscape’

    • ’a5portrait’

    • ’a5landscape’

    Default: ‘a5landscape’.

  • binwidth (float) – Width of bins. Default: None.

edisgo.tools.plots.add_basemap(ax, zoom=12)[source]

Adds map to a plot.

edisgo.tools.plots.get_grid_district_polygon(config, subst_id=None, projection=4326)[source]

Get MV network district polygon from oedb for plotting.

edisgo.tools.plots.mv_grid_topology(edisgo_obj, timestep=None, line_color=None, node_color=None, grid_expansion_costs=None, filename=None, arrows=False, grid_district_geom=True, background_map=True, limits_cb_lines=None, limits_cb_nodes=None, xlim=None, ylim=None, lines_cmap='inferno_r', title='', scaling_factor_line_width=None, curtailment_df=None, **kwargs)[source]

Plot line loading as color on lines.

Displays line loading relative to nominal capacity.

Parameters:
  • edisgo_obj (EDisGo)

  • timestep (pandas.Timestamp) – Time step to plot analysis results for. If timestep is None maximum line load and if given, maximum voltage deviation, is used. In that case arrows cannot be drawn. Default: None.

  • line_color (str or None) –

    Defines whereby to choose line colors (and implicitly size). Possible options are:

    • ’loading’ Line color is set according to loading of the line. Loading of MV lines must be provided by parameter line_load.

    • ’expansion_costs’ Line color is set according to investment costs of the line. This option also effects node colors and sizes by plotting investment in stations and setting node_color to ‘storage_integration’ in order to plot storage size of integrated storage units. Grid expansion costs must be provided by parameter grid_expansion_costs.

    • None (default) Lines are plotted in black. Is also the fallback option in case of wrong input.

  • node_color (str or None) –

    Defines whereby to choose node colors (and implicitly size). Possible options are:

    • ’technology’ Node color as well as size is set according to type of node (generator, MV station, etc.).

    • ’voltage’ Node color is set according to voltage at each node. In case several time steps are selected the maximum voltage is shown.

    • ’voltage_deviation’ Node color is set according to voltage deviation from 1 p.u.. In case several time steps are selected the maximum absolute voltage deviation from 1 p.u. is shown.

    • ’storage_integration’ Only storage units are plotted. Size of node corresponds to size of storage.

    • None (default) Nodes are not plotted. Is also the fallback option in case of wrong input.

    • ’curtailment’ Plots curtailment per node. Size of node corresponds to share of curtailed power for the given time span. When this option is chosen a dataframe with curtailed power per time step and node needs to be provided in parameter curtailment_df.

    • ’charging_park’ Plots nodes with charging stations in red.

  • line_load (pandas.DataFrame or None) – Dataframe with current results from power flow analysis in A. Index of the dataframe is a pandas.DatetimeIndex, columns are the line representatives. Only needs to be provided when parameter line_color is set to ‘loading’. Default: None.

  • grid_expansion_costs (pandas.DataFrame or None) – Dataframe with network expansion costs in kEUR. See grid_expansion_costs in Results for more information. Only needs to be provided when parameter line_color is set to ‘expansion_costs’. Default: None.

  • filename (str) – Filename to save plot under. If not provided, figure is shown directly. Default: None.

  • arrows (Boolean) – If True draws arrows on lines in the direction of the power flow. Does only work when line_color option ‘loading’ is used and a time step is given. Default: False.

  • grid_district_geom (Boolean) – If True network district polygon is plotted in the background. This also requires the geopandas package to be installed. Default: True.

  • background_map (Boolean) – If True map is drawn in the background. This also requires the contextily package to be installed. Default: True.

  • limits_cb_lines (tuple) – Tuple with limits for colorbar of line color. First entry is the minimum and second entry the maximum value. Only needs to be provided when parameter line_color is not None. Default: None.

  • limits_cb_nodes (tuple) – Tuple with limits for colorbar of nodes. First entry is the minimum and second entry the maximum value. Only needs to be provided when parameter node_color is not None. Default: None.

  • xlim (tuple) – Limits of x-axis. Default: None.

  • ylim (tuple) – Limits of y-axis. Default: None.

  • lines_cmap (str) – Colormap to use for lines in case line_color is ‘loading’ or ‘expansion_costs’. Default: ‘inferno_r’.

  • title (str) – Title of the plot. Default: ‘’.

  • scaling_factor_line_width (float or None) – If provided line width is set according to the nominal apparent power of the lines. If line width is None a default line width of 2 is used for each line. Default: None.

  • curtailment_df (pandas.DataFrame) – Dataframe with curtailed power per time step and node. Columns of the dataframe correspond to buses and index to the time step. Only needs to be provided if node_color is set to ‘curtailment’.

  • legend_loc (str) – Location of legend. See matplotlib legend location options for more information. Default: ‘upper left’.

edisgo.tools.plots.color_map_color(value: numbers.Number, vmin: numbers.Number, vmax: numbers.Number, cmap_name: str | list = 'coolwarm') str[source]

Get matching color for a value on a matplotlib color map.

Parameters:
  • value (float or int) – Value to get color for

  • vmin (float or int) – Minimum value on color map

  • vmax (float or int) – Maximum value on color map

  • cmap_name (str or list) – Name of color map to use, or the colormap

Returns:

Color name in hex format

Return type:

str

edisgo.tools.plots.plot_plotly(edisgo_obj: edisgo.EDisGo, grid: edisgo.network.grids.Grid | None = None, line_color: None | str = 'relative_loading', node_color: None | str = 'voltage_deviation', line_result_selection: str = 'max', node_result_selection: str = 'max', selected_timesteps: pandas.Timestamp | list | None = None, plot_map: bool = False, pseudo_coordinates: bool = False, node_selection: list | bool = False, height: int = 500) plotly.basedatatypes.BaseFigure[source]

Draws a plotly html figure.

Parameters:
  • edisgo_obj (EDisGo) – Selected edisgo_obj to get plotting information from.

  • grid (Grid) – Grid to plot. If None, the MVGrid of the edisgo_obj is plotted. Default: None.

  • line_color (str or None) –

    Defines whereby to choose line colors. Possible options are:

    • ’loading’

      Line color is set according to loading of the line.

    • ’relative_loading’ (default)

      Line color is set according to relative loading of the line.

    • ’reinforce’

      Line color is set according to investment costs of the line.

    • None

      Line color is black. This is also the fallback, in case other options fail.

  • node_color (str or None) –

    Defines whereby to choose node colors. Possible options are:

    • ’adjacencies’

      Node color as well as size is set according to the number of direct neighbors.

    • ’voltage_deviation’ (default)

      Node color is set according to voltage deviation from 1 p.u..

    • None

      Line color is black. This is also the fallback, in case other options fail.

  • line_result_selection (str) –

    Defines which values are shown for the load of the lines:

    • ’min’

      Minimal line load of all time steps.

    • ’max’ (default)

      Maximal line load of all time steps.

  • node_result_selection (str) –

    Defines which values are shown for the voltage of the nodes:

    • ’min’

      Minimal node voltage of all time steps.

    • ’max’ (default)

      Maximal node voltage of all time steps.

  • selected_timesteps (pandas.Timestamp or list(pandas.Timestamp) or None) –

    Selected time steps to show results for.

  • plot_map (bool) – Enable the plotting of a background map.

  • pseudo_coordinates (bool) – Enable pseudo coordinates for the plotted grid. Default: False.

  • node_selection (bool or list(str)) – Only plot selected nodes. Default: False.

  • height (int) – Height of the plotly plot in pixels.

Returns:

Plotly figure with branches and nodes.

Return type:

plotly.plotly.graph_objects.Figure

edisgo.tools.plots.chosen_graph(edisgo_obj: edisgo.EDisGo, selected_grid: str) tuple[networkx.Graph, bool | edisgo.network.grids.Grid][source]

Get the matching networkx graph from a chosen grid.

Parameters:
  • edisgo_obj (EDisGo)

  • selected_grid (str) – Grid name. Can be either ‘Grid’ to select the MV grid with all LV grids or the name of the MV grid to select only the MV grid or the name of one of the LV grids of the eDisGo object to select a specific LV grid.

Returns:

Tuple with the first entry being the networkx graph of the selected grid and the second entry the grid to use as root node. See draw_plotly() for more information.

Return type:

(networkx.Graph, Grid or bool)

edisgo.tools.plots.plot_dash_app(edisgo_objects: edisgo.EDisGo | dict[str, edisgo.EDisGo], debug: bool = False, height: int = 500) jupyter_dash.JupyterDash[source]

Generates a jupyter dash app from given eDisGo object(s).

Parameters:
  • edisgo_objects (EDisGo or dict[str, EDisGo]) – eDisGo objects to show in plotly dash app. In the case of multiple edisgo objects pass a dictionary with the eDisGo objects as values and the respective eDisGo object names as keys.

  • height (int) – Height of the plotly plot in pixels.

  • debug (bool) –

    Debugging for the dash app:

    • False (default)

      Disable debugging for the dash app.

    • True

      Enable debugging for the dash app.

Returns:

Jupyter dash app.

Return type:

JupyterDash

edisgo.tools.plots.plot_dash(edisgo_objects: edisgo.EDisGo | dict[str, edisgo.EDisGo], mode: str = 'inline', debug: bool = False, port: int = 8050, height: int = 820)[source]

Shows the generated jupyter dash app from given eDisGo object(s).

Parameters:
  • edisgo_objects (EDisGo or dict[str, EDisGo]) – eDisGo objects to show in plotly dash app. In the case of multiple edisgo objects pass a dictionary with the eDisGo objects as values and the respective eDisGo object names as keys.

  • mode (str) –

    Display mode

    • ”inline” (default)

      Jupyter lab inline plotting.

    • ”jupyterlab”

      Plotting in own Jupyter lab tab.

    • ”external”

      Plotting in own browser tab.

  • debug (bool) – If True, enables debugging of the jupyter dash app.

  • port (int) – Port which the app uses. Default: 8050.

  • height (int) – Height of the jupyter dash cell.