Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minimal example of plotly working with PyPSA - using Mapbox
mapbox_access_token = 'PASTE_YOUR_TOKEN_HERE'
import plotly.offline as py
from plotly.graph_objs import *
import plotly.graph_objs as go
import pypsa
py.init_notebook_mode(connected=True)
%matplotlib inline
#data available from https://github.com/FRESNA/PyPSA
n = pypsa.Network("./pypsa/examples/scigrid-de/scigrid-with-load-gen-trafos/")
edge_trace = Scattermapbox(
lat=[],
lon=[],
line=Line(width=0.5,color='#888'),
hoverinfo='none',
mode='lines')
for edge in n.lines.index:
x0, y0 = n.buses.at[n.lines.at[edge,"bus0"],"x"],n.buses.at[n.lines.at[edge,"bus0"],"y"]
x1, y1 = n.buses.at[n.lines.at[edge,"bus1"],"x"],n.buses.at[n.lines.at[edge,"bus1"],"y"]
edge_trace['lon'] += [x0, x1, None]
edge_trace['lat'] += [y0, y1, None]
node_trace = Scattermapbox(
lat=[],
lon=[],
text=[],
mode='markers',
hoverinfo='text',
marker=Marker(
showscale=True,
# colorscale options
# 'Greys' | 'Greens' | 'Bluered' | 'Hot' | 'Picnic' | 'Portland' |
# Jet' | 'RdBu' | 'Blackbody' | 'Earth' | 'Electric' | 'YIOrRd' | 'YIGnBu'
colorscale='YIGnBu',
reversescale=True,
color=[],
size=10,
colorbar=dict(
thickness=15,
title='Node Connections',
xanchor='left',
titleside='right'
),
# line=dict(width=2)
)
)
for node in n.buses.index:
x, y = n.buses.at[node,"x"],n.buses.at[node,"y"]
node_trace['lon'].append(x)
node_trace['lat'].append(y)
#for node, adjacencies in enumerate(G.adjacency_list()):
# node_trace['marker']['color'].append(len(adjacencies))
# node_info = '# of connections: '+str(len(adjacencies))
# node_trace['text'].append(node_info)
layout = go.Layout(
title='Nuclear Waste Sites on Campus',
autosize=True,
hovermode='closest',
showlegend=True,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=51,
lon=10
),
pitch=0,
zoom=4,
style='light'
),
)
fig = Figure(data=Data([edge_trace, node_trace]),
layout=layout
)
py.iplot(fig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.