Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'develop' into deprecationWarning
  • Loading branch information
jwiemer112 committed Feb 3, 2023
2 parents 0c58f56 + d318bda commit e12a5da
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 46 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.rst
Expand Up @@ -3,10 +3,12 @@ Change Log

[upcoming release] - 2023-..-..
-------------------------------
- [ADDED] feature: storing to json and restoring of nets with pandas multiindex dataframes and series
- [ADDED] several 'marker size legends' sizes + a spec. color can be passed to weighted_marker_traces
- [CHANGED] cim2pp converter documentation fixes
- [CHANGED] make legend item size constant in `simple_plotly`
- [FIXED] add (nan) field "coords" to bus geodata in create_cigre_network_hv to avoid fatal error when exporting to Excel
- [FIXED] documentation of powerfactory converter
- [CHANGED] cim2pp converter documentation fixes
- [ADDED] feature: storing to json and restoring of nets with pandas multiindex dataframes and series
- [FIXED] create.py: if optional arguments are None or nan, the optional columns will not be added
- [FIXED] add tap_dependent_impedance attributes to trafo3w instead of trafo, in create.create_transformer3w and create.create_transformer3w_from_parameters
- [ADDED] documentation of DeprecationWarning process
Expand Down
19 changes: 10 additions & 9 deletions pandapower/plotting/plotly/simple_plotly.py
Expand Up @@ -72,9 +72,10 @@ def get_hoverinfo(net, element, precision=3, sub_index=None):


def simple_plotly(net, respect_switches=True, use_line_geodata=None, on_map=False,
projection=None, map_style='basic', figsize=1, aspectratio='auto', line_width=1,
bus_size=10, ext_grid_size=20.0, bus_color="blue", line_color='grey',
trafo_color='green', trafo3w_color='green', ext_grid_color="yellow",
projection=None, map_style='basic', figsize=1.0, aspectratio='auto',
line_width=1.0, bus_size=10.0, ext_grid_size=20.0,
bus_color="blue", line_color='grey', trafo_color='green',
trafo3w_color='green', ext_grid_color="yellow",
filename='temp-plot.html', auto_open=True, showlegend=True,
additional_traces=None):
"""
Expand Down Expand Up @@ -178,8 +179,8 @@ def simple_plotly(net, respect_switches=True, use_line_geodata=None, on_map=Fals
# for weighted_marker_traces "meta" should include information for the "scale legend"
if ("meta" in weighted_trace) and (weighted_trace["meta"]["show_scale_legend"]):
sc_trace = create_scale_trace(net, weighted_trace, down_shift=shift)
traces.extend([sc_trace])
shift += 1
traces.extend(sc_trace)
shift += len(weighted_trace["meta"]["scale_marker_size"])

traces.extend(additional_traces)

Expand Down Expand Up @@ -238,21 +239,21 @@ def _simple_plotly_generic(net, respect_separators, use_branch_geodata, on_map,
trans_trace3w = []
ext_grid_trace = []
# ----- Trafos ------
if 'trafo' in net:
if 'trafo' in net and len(net.trafo):
hoverinfo = hoverinfo_func(net, element=trans_element)
trans_trace = create_trafo_trace(net, color=trafo_color, width=branch_width * 5,
infofunc=hoverinfo,
use_line_geodata=use_branch_geodata)
# ----- 3W Trafos ------
if 'trafo3w' in net:
if 'trafo3w' in net and len(net.trafo3w):
hoverinfo = hoverinfo_func(net, element=trans3w_element)
trans_trace3w = create_trafo_trace(net, color=trafo3w_color, trafotype='3W',
width=branch_width * 5,
trace_name='3W transformers', infofunc=hoverinfo,
use_line_geodata=use_branch_geodata)
# ----- Ext grid ------
# get external grid from _create_node_trace
if 'ext_grid' in net:
if 'ext_grid' in net and len(net.ext_grid):
marker_type = 'circle' if on_map else 'square' # workaround because doesn't appear on mapbox if square
hoverinfo = hoverinfo_func(net, element="ext_grid")
ext_grid_trace = _create_node_trace(net, nodes=net.ext_grid[node_element], size=ext_grid_size,
Expand All @@ -278,7 +279,7 @@ def _simple_plotly_generic(net, respect_separators, use_branch_geodata, on_map,
marker_scaling=100)
markers_sgen = create_weighted_marker_trace(net, elm_type="sgen", color="green",
patch_type="circle-open", sizemode="diameter",
marker_scaling=100, scale_marker_size=0.5)
marker_scaling=100, scale_marker_size=[0.2, 0.4])

fig = simple_plotly(net, bus_size=1, aspectratio="original", additional_traces=[markers_sgen,
markers_load])
86 changes: 51 additions & 35 deletions pandapower/plotting/plotly/traces.py
Expand Up @@ -789,7 +789,8 @@ def create_weighted_marker_trace(net, elm_type="load", elm_ids=None, column_to_p
sizemode="area", color="red", patch_type="circle",
marker_scaling=1., trace_name="", infofunc=None,
node_element="bus", show_scale_legend=True,
scale_marker_size=None):
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").
Expand Down Expand Up @@ -835,9 +836,16 @@ def create_weighted_marker_trace(net, elm_type="load", elm_ids=None, column_to_p
**show_scale_legend** (bool, default True): display a marker legend at the top right of the
plot
**scale_marker_size** (float, 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
**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
Expand Down Expand Up @@ -894,10 +902,17 @@ def create_weighted_marker_trace(net, elm_type="load", elm_ids=None, column_to_p
sizemode=sizemode)

# additional info for the create_scale_trace function:

if not isinstance(scale_marker_size, Iterable):
scale_marker_size = [scale_marker_size]

marker_trace["meta"] = dict(marker_scaling=marker_scaling,
column_to_plot=column_to_plot,
scale_legend_unit=scale_legend_unit or
column_to_plot.split("_")[1].upper(),
show_scale_legend=show_scale_legend,
scale_marker_size=scale_marker_size)
scale_marker_size=scale_marker_size,
scale_marker_color=scale_marker_color or color)

return marker_trace

Expand All @@ -920,43 +935,43 @@ def create_scale_trace(net, weighted_trace, down_shift=0):
"""
marker = weighted_trace["marker"]
scale_info = weighted_trace["meta"]
unit = scale_info["scale_legend_unit"] # p_mw...q_mvar ..

# scale trace
x_max, y_max = net.bus_geodata.x.max(), net.bus_geodata.y.max()
x_min, y_min = net.bus_geodata.x.min(), net.bus_geodata.y.min()

x_pos = x_max + (x_max - x_min) * 0.2
x_pos2 = x_max + ((x_max - x_min) * 0.2 * 2)
y_pos = y_max - ((y_max - y_min) * (0.2 * down_shift))

# p_mw...q_mvar ..
unit = scale_info["column_to_plot"].split("_")[1].upper()

# default is the average rounded to 5
if not scale_info["scale_marker_size"]:
scale_size = math.ceil(marker["size"].mean() / 5) * 5
scale_traces = []
for idx, sze in enumerate(scale_info["scale_marker_size"]):
y_pos = y_max - ((y_max - y_min) * (0.2 * (down_shift + idx)))

else:
scale_size = scale_info["scale_marker_size"] * scale_info['marker_scaling']

# second (dummy) position is needed for correct marker sizing
scale_trace = dict(type="scatter",
x=[x_pos, x_pos2],
y=[y_pos, y_pos],
mode="markers+text",
hoverinfo="skip",
marker=dict(size=[scale_size, 0],
color=marker['color'],
symbol=marker["symbol"],
sizemode=marker["sizemode"]),
text=[f"scale: {scale_size / scale_info['marker_scaling']} {unit}", ""],
textposition="top center",
showlegend=False,
textfont=dict(
family="Helvetica",
size=14,
color="DarkSlateGrey"))

return scale_trace
# default is the average rounded to 5
if not sze:
scale_size = math.ceil(marker["size"].mean() / 5) * 5
else:
scale_size = sze * scale_info['marker_scaling']

# second (dummy) position is needed for correct marker sizing
scale_trace = dict(type="scatter",
x=[x_pos, x_pos2],
y=[y_pos, y_pos],
mode="markers+text",
hoverinfo="skip",
marker=dict(size=[scale_size, 0],
color=scale_info.get("scale_marker_color"),
symbol=marker["symbol"],
sizemode=marker["sizemode"]),
text=[f"{scale_size / scale_info['marker_scaling']} {unit}", ""],
textposition="top center",
showlegend=False,
textfont=dict(family="Helvetica",
size=14,
color="DarkSlateGrey"))
scale_traces.append(scale_trace)

return scale_traces


def draw_traces(traces, on_map=False, map_style='basic', showlegend=True, figsize=1,
Expand Down Expand Up @@ -1045,6 +1060,7 @@ def draw_traces(traces, on_map=False, map_style='basic', showlegend=True, figsiz
xaxis=XAxis(showgrid=False, zeroline=False, showticklabels=False),
yaxis=YAxis(showgrid=False, zeroline=False, showticklabels=False),
# legend=dict(x=0, y=1.0)
legend={'itemsizing': 'constant'},
),
)
a = kwargs.get('annotation')
Expand Down

0 comments on commit e12a5da

Please sign in to comment.