color buses in pandapower network plot

800 views Asked by At

I want to choose the color for certain buses in the graph of a pandapower network. I use the simple_plotly function from pandapower, which works well. As a next step I use create_bus_trace here to crate a trace. Finally I use draw_traces here to draw those buses.

PROBLEM:
The trace appears in a separate plot. But I want the trace to be in the same plot as that, created with simple_plotly(net)

Here is, what my code looks like:

import numpy as np
import pandapower.plotting as pt
import pandapower as pp
import pandapower.networks as pn

net = pn.create_kerber_vorstadtnetz_kabel_1()
pt.simple_plotly(net)

color_buses = np.random.choice(net.bus.index, 33)
color_trace = pt.plotly.create_bus_trace(net, color_buses, color='red',
                                         trace_name='special buses')
pt.plotly.draw_traces(color_trace)

Any ideas, how to get both traces into one plot?

Thank you for any help in advance!

1

There are 1 answers

0
Andre On

I have found a solution:

import numpy as np
import pandapower.plotting as pt
import pandapower as pp
import pandapower.networks as pn
import plotly
import plotly.graph_objs as go
import plotly.graph_objs as go
import plotly.io as pio
pio.renderers.default = 'browser'

net = pn.create_kerber_vorstadtnetz_kabel_1()
fig = pt.simple_plotly(net)

how_much_buses = 33
color_buses = np.random.choice(net.bus.index, how_much_buses)

fig.add_trace(go.Scatter(x=net.bus_geodata.loc[color_buses, 'x'],
                         y=net.bus_geodata.loc[color_buses, 'y'],
                         mode='markers'))

fig.show()

So the trick was to directly work with the object returned by simple_plotly and use add_trace.
I also had to tell plotly.io to use the browser as standard renderer for the updated plot to appear on fig.show().

This is what it looks like:

enter image description here