Plotting traces (collections)

This Tutorial explains how to customize network plots in pandapower using plotly. Each pandapower network element can be translated into a plotly trace with all corresponding properties...

In [1]:
import pandapower as pp
import pandapower.networks as nw
import pandapower.plotting.plotly as pplotly
from pandas import Series
import numpy as np

We created a network along with geodata in the buses.

In [2]:
net = pp.create_empty_network()
x=np.array([0,-2,2,-3,-2,2])
y=np.array([4,3,3,-3,-2,-2])
for i in range(6):
    if i < 3:
            v = 110
    elif i == 3:
            v = 20    
    else:
            v=10
    pp.create_bus(net, vn_kv=v,geodata=(x[i], y[i]))

pp.create_line(net, 0, 1, 5, "149-AL1/24-ST1A 110.0",geodata=None,name='l1')
pp.create_line(net, 0, 2, 5, "149-AL1/24-ST1A 110.0",geodata=None,name='l2')
pp.create_transformer3w(net, 1, 3, 4, "63/25/38 MVA 110/20/10 kV", name='tr1')


pp.create_transformer(net, 2, 5, "0.25 MVA 20/0.4 kV", name='tr2')


pp.create_ext_grid(net, 0)
pp.create_load(net, 4, p_mw=20., q_mvar=10., name='load1')
pp.create_load(net, 5, p_mw=20., q_mvar=10., name='load1')
Out[2]:
1

If you want to have full control over the layout of your plot, you can individually create and plot collections with the pandapower plotting module.

In [3]:
lc = pplotly.create_line_trace(net,net.line.index, color='black',infofunc=net.line.name)
bc = pplotly.create_bus_trace(net, net.bus.index, size=10, color="orange",infofunc=net.bus.vn_kv)
tc3 = pplotly.create_trafo_trace(net, net.trafo3w.index,trafotype='3W', color='green', infofunc=net.trafo3w.name,trace_name='trafo3ws', cmin=None, cmax=None, cmap_vals=None,use_line_geodata=None)
tc = pplotly.create_trafo_trace(net, net.trafo.index, trafotype='2W',color='blue', infofunc=net.trafo.name,trace_name='trafos', cmin=None, cmax=None, cmap_vals=None,use_line_geodata=None)
pplotly.draw_traces(bc+lc+tc+tc3, figsize=1, aspectratio=(8,4));