Create & Draw Traces
Plotly traces can be created from pandapower networks with the following functions.
The traces can be passed as additional_traces
(list) to the simple_plotly()
function.
Bus Traces
- pandapower.plotting.plotly.traces.create_bus_trace(net, buses=None, size=5, patch_type='circle', color='blue', infofunc=None, trace_name='buses', legendgroup=None, cmap=None, cmap_vals=None, cbar_title=None, cmin=None, cmax=None, cpos=1.0, colormap_column='vm_pu')
Creates a plotly trace of pandapower buses. It is a wrapper function for the more generic _create_node_trace function.
- INPUT:
net (pandapowerNet) - The pandapower network
- OPTIONAL:
buses (list, None) - The buses for which the collections are created. If None, all buses in the network are considered.
size (int, 5) - patch size
patch_type (str, “circle”) - patch type, can be
“circle” for a circle
“square” for a rectangle
“diamond” for a diamond
much more patch types at https://plot.ly/python/reference/#scatter-marker
infofunc (pd.Series, None) - hoverinfo for bus elements. Indices should correspond to the pandapower element indices
trace_name (String, “buses”) - name of the trace which will appear in the legend
color (String, “blue”) - color of buses in the trace
cmap (String, None) - name of a colormap which exists within plotly (Greys, YlGnBu, Greens, YlOrRd, Bluered, RdBu, Reds, Blues, Picnic, Rainbow, Portland, Jet, Hot, Blackbody, Earth, Electric, Viridis) alternatively a custom discrete colormap can be used. Append “_r” for inversion.
cmap_vals (list, None) - values used for coloring using colormap
cbar_title (String, None) - title for the colorbar
cmin (float, None) - colorbar range minimum
cmax (float, None) - colorbar range maximum
cpos (float, 1.1) - position of the colorbar
colormap_column (str, “vm_pu”) - set color of bus according to this variable
Branch Traces
- pandapower.plotting.plotly.traces.create_line_trace(net, lines=None, use_line_geo=True, respect_switches=False, width=1.0, color='grey', infofunc=None, trace_name='lines', legendgroup='lines', cmap=None, cbar_title=None, show_colorbar=True, cmap_vals=None, cmin=None, cmax=None, cpos=1.1, cmap_vals_category='loading_percent', hoverlabel=None, dash='solid')
Creates a plotly trace of pandapower lines. It is a power net specific wrapper function for the more generic _create_line_trace function.
- INPUT:
net (pandapowerNet) - The pandapower network
- OPTIONAL:
lines (list, None) - The lines for which the collections are created. If None, all lines in the network are considered.
width (int, 1) - line width
infofunc (pd.Series, None) - hoverinfo for line elements. Indices should correspond to the pandapower element indices
trace_name (String, “lines”) - name of the trace which will appear in the legend
color (String, “grey”) - color of lines in the trace
legendgroup (String, None) - defines groups of layers that will be displayed in a legend e.g. groups according to voltage level (as used in vlevel_plotly)
cmap (String, None) - name of a colormap which exists within plotly if set to True default Jet colormap is used, alternative colormaps : Greys, YlGnBu, Greens, YlOrRd, Bluered, RdBu, Reds, Blues, Picnic, Rainbow, Portland, Jet, Hot, Blackbody, Earth, Electric, Viridis To revert the color map, append “_r” to the name.
cmap_vals (list, None) - values used for coloring using colormap
show_colorbar (bool, False) - flag for showing or not corresponding colorbar
cbar_title (String, None) - title for the colorbar
cmin (float, None) - colorbar range minimum
cmax (float, None) - colorbar range maximum
cpos (float, 1.1) - position of the colorbar
- pandapower.plotting.plotly.traces.create_trafo_trace(net, trafos=None, color='green', trafotype='2W', width=5, infofunc=None, cmap=None, trace_name='2W transformers', cmin=None, cmax=None, cmap_vals=None, matching_params=None, use_line_geo=None)
Creates a plotly trace of pandapower trafos.
- INPUT:
net (pandapowerNet) - The pandapower network
- OPTIONAL:
trafos (list, None) - The trafos for which the collections are created. If None, all trafos in the network are considered.
trafotype (String, “2W”) - trafotype can be 2W or 3W and can define which transformer table is taken (trafo or trafo3w)
width (int, 5) - line width
infofunc (pd.Series, None) - hoverinfo for trafo elements. Indices should correspond to the pandapower element indices
trace_name (String, “lines”) - name of the trace which will appear in the legend
color (String, “green”) - color of lines in the trace
cmap (bool, False) - name of a colormap which exists within plotly (Greys, YlGnBu, Greens, YlOrRd, Bluered, RdBu, Reds, Blues, Picnic, Rainbow, Portland, Jet, Hot, Blackbody, Earth, Electric, Viridis)
cmap_vals (list, None) - values used for coloring using colormap
cbar_title (String, None) - title for the colorbar
cmin (float, None) - colorbar range minimum
cmax (float, None) - colorbar range maximum
Draw Traces
- pandapower.plotting.plotly.traces.draw_traces(traces, on_map=False, map_style='basic', showlegend=True, figsize=1, aspectratio='auto', filename='temp-plot.html', auto_open=True, **kwargs)
plots all the traces (which can be created using
create_bus_trace()
,create_line_trace()
,create_trafo_trace()
) to PLOTLY (see https://plot.ly/python/)- INPUT:
traces - list of dicts which correspond to plotly traces generated using: create_bus_trace, create_line_trace, create_trafo_trace
- OPTIONAL:
on_map (bool, False) - enables using mapbox plot in plotly
map_style (str, ‘basic’) - enables using mapbox plot in plotly
‘streets’
‘bright’
‘light’
‘dark’
‘satellite’
showlegend (bool, ‘True’) - enables legend display
figsize (float, 1) - aspectratio is multiplied by it in order to get final image size
aspectratio (tuple, ‘auto’) - when ‘auto’ it preserves original aspect ratio of the network geodata any custom aspectration can be given as a tuple, e.g. (1.2, 1)
filename (str, “temp-plot.html”) - plots to a html file called filename
auto_open (bool, ‘True’) - automatically open plot in browser
- OUTPUT:
figure (graph_objs._figure.Figure) figure object
Markers with weighted size
The function create_weighted_marker_trace()
can be used to create additional traces with markers
(patches) for one column in one component table.
- pandapower.plotting.plotly.traces.create_weighted_marker_trace(net, elm_type='load', elm_ids=None, column_to_plot='p_mw', sizemode='area', color='red', patch_type='circle', marker_scaling=1.0, trace_name='', infofunc=None, node_element='bus', show_scale_legend=True, scale_marker_size=None, scale_marker_color=None, scale_legend_unit=None)
Create a single-color plotly trace markers/patches (e.g., bubbles) of value-dependent size.
Can be used with pandapipes.plotting.plotly.simple_plotly (pass as “additional_trace”). If present in the respective pandapower-net table, the “in_service” and “scaling” column will be taken into account as factors to calculate the markers’ weights. Negative values might lead to unexpected results, especially when pos. and neg. values are mixed in one column! All values are treated as absolute values. If value = 0, no marker will be created.
- INPUT:
net (pandapowerNet) - the pandapower net of the plot
- OPTIONAL:
elm_type (str, default “load”) - the element table in the net that holds the values to plot
elm_ids (list, default None) - the element IDs of the elm_type table for which markers will be created. If None, all IDs in net[elm_type] that are not 0 or NaN in the column_to_plot will be used.
column_to_plot (str, default “p_mw”) - the column in the net[elm_type] table that will be plotted. The suffix (everything behind the last ‘_’ in the column name) will be used as the unit in the infofunction.
sizemode (str, default “area”) - whether the markers’ “area” or “diameter” will be proportional to the represented value
color (str, default “red”) - color for the markers
patch_type (str, default “circle”) - plotly marker style that will be used (other options are triangle-up, triangle-down and many more; for non-filled markers, append “-open” cf. https://plotly.com/python/marker-style/)
marker_scaling (float, default 1.) - factor to scale the size of all markers
trace_name (str, default “”): trace name for the legend. If empty, elm_type will be used.
infofunc (pd.Series, default None): hover-infofuction to overwrite the internal infofunction
node_element (str, default “bus”) - the name of node elements in the net. “bus” for pandapower networks, “junction” for pandapipes networks
- show_scale_legend (bool, default True): display a marker legend at the top right of the
plot
scale_marker_size (float / list of floats, default None): adjust the size of the scale, gets multiplied with marker_scaling. Default size is the average size of the respective weighted markers rounded to 5. A list of values will result in several scale marker legends.
scale_marker_color (str, default None): specify the color of the scale legend marker. If None, color will be used.
scale_legend_unit (str, default None): specifies the unit shown in the scale legend marker’s string. It does not trigger any unit conversions! If None, the last part of column_to_plot will be used (all upper case).
- OUTPUT:
marker_trace (dict): dict for the plotly trace
Example with load and sgen bubbles:
net = mv_oberrhein()
net.load.scaling, net.sgen.scaling = 1, 1
markers_load = create_weighted_marker_trace(net, elm_type="load", color="red",
marker_scaling=100)
markers_sgen = create_weighted_marker_trace(net, elm_type="sgen", color="green",
marker_scaling=100)
simple_plotly(net, bus_size=1, additional_traces=[markers_load, markers_sgen])