Plots on Mapbox maps are available only considering you have a Mapbox account and a Mapbox Access Token. After getting a mabox token it can be written set to pandapower as the following (where '<token>'
needs to be replaced with provided mapbox token)
from pandapower.plotting.plotly.mapbox_plot import set_mapbox_token
set_mapbox_token('<token>')
If network geodata are in Geographic coordinate system as latitude/longitude, a network can be plot on different maps. Moreover, if network geodata are not in latitude/longitude, but in some of the projections, it may be converted to lat/long by providing name of the projection (in the form 'epsg:projection_number'according to http://spatialreference.org/ref/epsg/).
Following example shows plot of the network mv_oberrhein, where network geodata are in Gauss-Kruger projection (zone 3).
Since geodata are not in lat/long, plot using only on_map=True
cannot be realized on a map:
from pandapower.plotting.plotly import simple_plotly, pf_res_plotly, vlevel_plotly
from pandapower.networks import mv_oberrhein
net = mv_oberrhein()
The plot can be obtained if one knows specific projection and zone. In this case it is 3-degree Gauss-Kruger zone 3, which corresponds to epsg:31467:
net = mv_oberrhein()
simple_plotly(net, on_map=True, projection='epsg:31467');
C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 return _prepare_from_string(" ".join(pjargs)) C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:294: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 projstring = _prepare_from_string(" ".join((projstring, projkwargs))) C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 return _prepare_from_string(" ".join(pjargs)) C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:294: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 projstring = _prepare_from_string(" ".join((projstring, projkwargs))) Geo-coordinates check cannot be peformed because geopy package not available --> if geo-coordinates are not in lat/lon format an empty plot may appear...
There is a function available in pandapower which uses pyproj
to transform geodata from a projection to WGS84 (lat/long). It transforms and replaces net.bus_geodata
and net.line_geodata
(if existing). An example for mv_oberreihn
:
net = mv_oberrhein()
print('before:\n', net.bus_geodata.head())
from pandapower.plotting.plotly.mapbox_plot import geo_data_to_latlong
geo_data_to_latlong(net, projection='epsg:31467')
print('\nafter:\n', net.bus_geodata.head())
before: x y coords 0 3.408665e+06 5.364415e+06 None 1 3.409669e+06 5.364283e+06 None 100 3.419617e+06 5.365543e+06 None 101 3.412068e+06 5.366341e+06 None 102 3.419698e+06 5.365915e+06 None
C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:294: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:294: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
after: x y coords 0 7.765230 48.410903 None 1 7.778814 48.409858 None 100 7.912919 48.422542 None 101 7.810785 48.428703 None 102 7.913938 48.425895 None
The following map styles are available:
simple_plotly(net, on_map=True,map_style='satellite');
Geo-coordinates check cannot be peformed because geopy package not available --> if geo-coordinates are not in lat/lon format an empty plot may appear...
net = mv_oberrhein()
simple_plotly(net, on_map=True, projection='epsg:31467', map_style='streets');
C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:294: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 C:\Users\ssnigdha\miniconda3\envs\pandapower\lib\site-packages\pyproj\crs\crs.py:294: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 Geo-coordinates check cannot be peformed because geopy package not available --> if geo-coordinates are not in lat/lon format an empty plot may appear...
pf_res_plotly(net, on_map=True, map_style='dark');
Geo-coordinates check cannot be peformed because geopy package not available --> if geo-coordinates are not in lat/lon format an empty plot may appear...
More tutorials about interactive plots using ploltly: