edisgo.tools.plots ================== .. py:module:: edisgo.tools.plots Functions --------- .. autoapisummary:: edisgo.tools.plots.histogram edisgo.tools.plots.add_basemap edisgo.tools.plots.get_grid_district_polygon edisgo.tools.plots.mv_grid_topology edisgo.tools.plots.color_map_color edisgo.tools.plots.plot_plotly edisgo.tools.plots.chosen_graph edisgo.tools.plots.plot_dash_app edisgo.tools.plots.plot_dash Module Contents --------------- .. py:function:: histogram(data, **kwargs) Function to create histogram, e.g. for voltages or currents. :param data: Data to be plotted, e.g. voltage or current (`v_res` or `i_res` from :class:`network.results.Results`). Index of the dataframe must be a :pandas:`pandas.DatetimeIndex`. :type data: :pandas:`pandas.DataFrame` :param timeindex: Specifies time steps histogram is plotted for. If timeindex is None all time steps provided in `data` are used. Default: None. :type timeindex: :pandas:`pandas.Timestamp` or list(:pandas:`pandas.Timestamp`) or None, optional :param directory: Path to directory the plot is saved to. Is created if it does not exist. Default: None. :type directory: :obj:`str` or None, optional :param filename: Filename the plot is saved as. File format is specified by ending. If filename is None, the plot is shown. Default: None. :type filename: :obj:`str` or None, optional :param color: Color used in plot. If None it defaults to blue. Default: None. :type color: :obj:`str` or None, optional :param alpha: Transparency of the plot. Must be a number between 0 and 1, where 0 is see through and 1 is opaque. Default: 1. :type alpha: :obj:`float`, optional :param title: Plot title. Default: None. :type title: :obj:`str` or None, optional :param x_label: Label for x-axis. Default: "". :type x_label: :obj:`str`, optional :param y_label: Label for y-axis. Default: "". :type y_label: :obj:`str`, optional :param normed: Defines if histogram is normed. Default: False. :type normed: :obj:`bool`, optional :param x_limits: Tuple with x-axis limits. First entry is the minimum and second entry the maximum value. Default: None. :type x_limits: :obj:`tuple` or None, optional :param y_limits: Tuple with y-axis limits. First entry is the minimum and second entry the maximum value. Default: None. :type y_limits: :obj:`tuple` or None, optional :param fig_size: Size of the figure in inches or a string with the following options: * 'a4portrait' * 'a4landscape' * 'a5portrait' * 'a5landscape' Default: 'a5landscape'. :type fig_size: :obj:`str` or :obj:`tuple`, optional :param binwidth: Width of bins. Default: None. :type binwidth: :obj:`float` .. py:function:: add_basemap(ax, zoom=12) Adds map to a plot. .. py:function:: get_grid_district_polygon(config, subst_id=None, projection=4326) Get MV network district polygon from oedb for plotting. .. py:function:: 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) Plot line loading as color on lines. Displays line loading relative to nominal capacity. :param edisgo_obj: :type edisgo_obj: :class:`~edisgo.EDisGo` :param timestep: 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. :type timestep: :pandas:`pandas.Timestamp` :param line_color: 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. :type line_color: :obj:`str` or None :param node_color: 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. :type node_color: :obj:`str` or None :param line_load: Dataframe with current results from power flow analysis in A. Index of the dataframe is a :pandas:`pandas.DatetimeIndex`, columns are the line representatives. Only needs to be provided when parameter `line_color` is set to 'loading'. Default: None. :type line_load: :pandas:`pandas.DataFrame` or None :param grid_expansion_costs: Dataframe with network expansion costs in kEUR. See `grid_expansion_costs` in :class:`~.network.results.Results` for more information. Only needs to be provided when parameter `line_color` is set to 'expansion_costs'. Default: None. :type grid_expansion_costs: :pandas:`pandas.DataFrame` or None :param filename: Filename to save plot under. If not provided, figure is shown directly. Default: None. :type filename: :obj:`str` :param arrows: 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. :type arrows: :obj:`Boolean` :param grid_district_geom: If True network district polygon is plotted in the background. This also requires the geopandas package to be installed. Default: True. :type grid_district_geom: :obj:`Boolean` :param background_map: If True map is drawn in the background. This also requires the contextily package to be installed. Default: True. :type background_map: :obj:`Boolean` :param limits_cb_lines: 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. :type limits_cb_lines: :obj:`tuple` :param limits_cb_nodes: 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. :type limits_cb_nodes: :obj:`tuple` :param xlim: Limits of x-axis. Default: None. :type xlim: :obj:`tuple` :param ylim: Limits of y-axis. Default: None. :type ylim: :obj:`tuple` :param lines_cmap: Colormap to use for lines in case `line_color` is 'loading' or 'expansion_costs'. Default: 'inferno_r'. :type lines_cmap: :obj:`str` :param title: Title of the plot. Default: ''. :type title: :obj:`str` :param scaling_factor_line_width: 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. :type scaling_factor_line_width: :obj:`float` or None :param curtailment_df: 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'. :type curtailment_df: :pandas:`pandas.DataFrame` :param legend_loc: Location of legend. See matplotlib legend location options for more information. Default: 'upper left'. :type legend_loc: str .. py:function:: color_map_color(value, vmin, vmax, cmap_name = 'coolwarm') Get matching color for a value on a matplotlib color map. :param value: Value to get color for :type value: float or int :param vmin: Minimum value on color map :type vmin: float or int :param vmax: Maximum value on color map :type vmax: float or int :param cmap_name: Name of color map to use, or the colormap :type cmap_name: str or list :returns: Color name in hex format :rtype: str .. py:function:: plot_plotly(edisgo_obj, grid = None, line_color = 'relative_loading', node_color = 'voltage_deviation', line_result_selection = 'max', node_result_selection = 'max', selected_timesteps = None, plot_map = False, pseudo_coordinates = False, node_selection = False, height = 500) Draws a plotly html figure. :param edisgo_obj: Selected edisgo_obj to get plotting information from. :type edisgo_obj: :class:`~.EDisGo` :param grid: Grid to plot. If None, the MVGrid of the edisgo_obj is plotted. Default: None. :type grid: :class:`~.network.grids.Grid` :param line_color: 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. :type line_color: str or None :param node_color: 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. :type node_color: str or None :param line_result_selection: 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. :type line_result_selection: str :param node_result_selection: 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. :type node_result_selection: str :param selected_timesteps: Selected time steps to show results for. * None (default) All time steps are used. * list(:pandas:`pandas.Timestamp`) or :pandas:`pandas.Timestamp` Selected time steps are used. :type selected_timesteps: :pandas:`pandas.Timestamp` or list(:pandas:`pandas.Timestamp`) or None :param plot_map: Enable the plotting of a background map. :type plot_map: bool :param pseudo_coordinates: Enable pseudo coordinates for the plotted grid. Default: False. :type pseudo_coordinates: bool :param node_selection: Only plot selected nodes. Default: False. :type node_selection: bool or list(str) :param height: Height of the plotly plot in pixels. :type height: int :returns: Plotly figure with branches and nodes. :rtype: :plotly:`plotly.graph_objects.Figure` .. py:function:: chosen_graph(edisgo_obj, selected_grid) Get the matching networkx graph from a chosen grid. :param edisgo_obj: :type edisgo_obj: :class:`~.EDisGo` :param selected_grid: 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. :type selected_grid: str :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 :py:func:`~edisgo.tools.plots.draw_plotly` for more information. :rtype: (:networkx:`networkx.Graph<>`, :class:`~.network.grids.Grid` or bool) .. py:function:: plot_dash_app(edisgo_objects, debug = False, height = 500) Generates a dash app from given eDisGo object(s). :param edisgo_objects: 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. :type edisgo_objects: :class:`~.EDisGo` or dict[str, :class:`~.EDisGo`] :param height: Height of the plotly plot in pixels. :type height: int :param debug: Debugging for the dash app: * False (default) Disable debugging for the dash app. * True Enable debugging for the dash app. :type debug: bool :returns: dash app. :rtype: Dash .. py:function:: plot_dash(edisgo_objects, mode = 'inline', debug = False, port = 8050, height = 820) Shows the generated dash app from given eDisGo object(s). :param edisgo_objects: 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. :type edisgo_objects: :class:`~.EDisGo` or dict[str, :class:`~.EDisGo`] :param mode: Display mode * "inline" (default) Jupyter lab inline plotting. * "jupyterlab" Plotting in own Jupyter lab tab. * "external" Plotting in own browser tab. :type mode: str :param debug: If True, enables debugging of the dash app. :type debug: bool :param port: Port which the app uses. Default: 8050. :type port: int :param height: Height of the dash cell. :type height: int