Skip to content

Commit 6566e30

Browse files
authored
Merge pull request #2740 from KS-HTK/issues/plotly-markers
Updated docs for plotly
2 parents f6cac9a + 58f7eaa commit 6566e30

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

doc/plotting/plotly/plotly.rst

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,17 @@ pandapower provides interactive network plots using `Plotly <https://plot.ly/pyt
66
These plots are built with arguments and functionalities to be as much as possible analogous with pandapower's
77
matlpotlib plotting library.
88
There is a functionality to translate pandapower network elements into plotly collections (traces).
9-
The different collections for lines, buses or transformers can than be drawn.
9+
The different collections for lines, buses or transformers can then be drawn.
1010

1111
In order to get idea about interactive plot features and possibilities see the `tutorial <http://nbviewer.jupyter.org/github/e2nIEE/pandapower/blob/develop/tutorials/plotly_built-in.ipynb>`_.
1212

13-
1413
If a network has geocoordinates, there is a possibility to represent interactive plots on `MapLibre <https://maplibre.org/>`_ maps.
1514

1615
.. note::
1716

18-
Plots on MapLibre maps are free.
19-
Previously Plotly library used `Mapbox <https://www.mapbox.com/>`_ services which were working
20-
only considering you have a Mapbox account and a `Mapbox Access Token <https://www.mapbox.com/studio>`_.
21-
22-
In previous pandapower versions (until v3.1.3) there was a functionality to
23-
set and get a Mapbox token in pandapower.
24-
After getting a mapbox token it can be set to pandapower as the following ::
25-
26-
from pandapower.plotting.plotly.mapbox_plot import set_mapbox_token
27-
set_mapbox_token('<token>')
28-
29-
This functionality is still working but deprecated and useless in future
17+
Previously Plotly library used `Mapbox <https://www.mapbox.com/>`_ services which required
18+
a Mapbox account and a `Mapbox Access Token <https://www.mapbox.com/studio>`_.
19+
Setting and getting the token is deprecated and will be removed in a future
3020
pandapower releases.
3121

3222
.. toctree::

pandapower/plotting/plotly/mapbox_plot.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
# Copyright (c) 2016-2023 by University of Kassel and Fraunhofer Institute for Energy Economics
44
# and Energy System Technology (IEE), Kassel. All rights reserved.
55

6-
76
import os
8-
97
from typing_extensions import deprecated
10-
11-
from pandapower.plotting.geo import convert_crs
12-
138
import logging
149

1510
logger = logging.getLogger(__name__)

pandapower/plotting/plotly/simple_plotly.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ def _simple_plotly_generic(net, respect_separators, use_branch_geodata, branch_w
317317
# get external grid from _create_node_trace
318318
if 'ext_grid' in net and len(net.ext_grid):
319319
marker_type = 'circle' if settings['on_map'] else 'square' # better would be square-x
320-
# FIXME: workaround because doesn't appear on mapbox if square
320+
# FIXME: if on_map only maki 2.1 Icons are supported as patch_type due to plotly using them.
321+
# Only the circle can be colored and scaled. https://github.com/plotly/plotly.js/issues/6599
321322
hoverinfo = hoverinfo_func(net, element="ext_grid")
322323
ext_grid_trace = _create_node_trace(
323324
net,

pandapower/plotting/plotly/traces.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,20 @@ def create_edge_center_trace(line_trace, size=1, patch_type="circle", color="whi
9797
"""
9898
# color = get_plotly_color(color)
9999

100-
center_trace = dict(type='scatter', text=[], mode='markers', hoverinfo='text', name=trace_name,
101-
marker=dict(color=color, size=size, symbol=patch_type),
102-
showlegend=showlegend, legendgroup=legendgroup)
100+
center_trace = {
101+
"type": 'scatter',
102+
"text": [],
103+
"mode": 'markers',
104+
"hoverinfo": 'text',
105+
"name": trace_name,
106+
"marker": {
107+
"color": color,
108+
"size": size,
109+
"symbol": patch_type
110+
},
111+
"showlegend": showlegend,
112+
"legendgroup": legendgroup
113+
}
103114
if hoverlabel is not None:
104115
center_trace.update({'hoverlabel': hoverlabel})
105116

@@ -141,7 +152,8 @@ def create_bus_trace(net, buses=None, size=5, patch_type="circle", color="blue",
141152
- "circle" for a circle
142153
- "square" for a rectangle
143154
- "diamond" for a diamond
144-
- much more patch types at https://plot.ly/python/reference/#scatter-marker
155+
- all types for plots at https://plotly.com/python/reference/#scatter-marker-symbol
156+
- all types for maps at https://plotly.com/python/reference/#scatter-marker-symbol
145157
146158
**infofunc** (pd.Series, None) - hoverinfo for bus elements. Indices should correspond to
147159
the pandapower element indices
@@ -248,8 +260,18 @@ def _create_node_trace(net, nodes=None, size=5, patch_type='circle', color='blue
248260
if not PLOTLY_INSTALLED:
249261
soft_dependency_error(str(sys._getframe().f_code.co_name) + "()", "plotly")
250262
color = get_plotly_color(color)
251-
node_trace = dict(type='scatter', text=[], mode='markers', hoverinfo='text', name=trace_name,
252-
marker=dict(color=color, size=size, symbol=patch_type))
263+
node_trace = {
264+
"type": 'scatter',
265+
"text": [],
266+
"mode": 'markers',
267+
"hoverinfo": 'text',
268+
"name": trace_name,
269+
"marker": {
270+
"color": color,
271+
"size": size,
272+
"symbol": patch_type
273+
}
274+
}
253275
nodes = net[node_element].index.tolist() if nodes is None else list(nodes)
254276
node_plot_index = [b for b in nodes if b in list(set(nodes) & set(net[node_element]["geo"].index))]
255277
node_trace['x'], node_trace['y'] = zip(*net[node_element].loc[node_plot_index, 'geo'].dropna().apply(geojson.loads).apply(geojson.utils.coords).apply(next).to_list())
@@ -262,7 +284,7 @@ def _create_node_trace(net, nodes=None, size=5, patch_type='circle', color='blue
262284
node_trace['legendgroup'] = legendgroup
263285
# if color map is set
264286
if cmap is not None:
265-
# TODO introduce discrete colormaps (see contour plots in plotly)
287+
# TODO: introduce discrete colormaps (see contour plots in plotly)
266288
# if cmap_vals are not given
267289

268290
cmap = 'Jet' if cmap is True else cmap
@@ -598,7 +620,7 @@ def _create_branch_trace(net, branches=None, use_branch_geodata=True, respect_se
598620
if cmap is not None:
599621
# workaround: if colormap plot is used, each line need to be separate scatter object because
600622
# plotly still doesn't support appropriately colormap for line objects
601-
# TODO correct this when plotly solves existing github issue about Line colorbar
623+
# TODO: correct this when plotly solves existing github issue about Line colorbar
602624

603625
cmap = 'jet' if cmap is True else cmap
604626

@@ -1114,8 +1136,8 @@ def draw_traces(traces, on_map=False, map_style='basic', showlegend=True, figsiz
11141136
trace['lat'] = trace.pop('y')
11151137
trace['type'] = 'scattermap'
11161138
if "line" in trace and isinstance(trace["line"], Line):
1117-
# scattermapboxplot lines do not support dash for some reason, make it a red line instead
1118-
# --> maybe Dash is working now ?
1139+
# scattermap plot lines do not support dash for some reason, make it a red line instead
1140+
# TODO: maybe Dash is working now?
11191141
if "dash" in trace["line"]._props:
11201142
_prps = dict(trace["line"]._props)
11211143
_prps.pop("dash")

0 commit comments

Comments
 (0)