Skip to content

Commit b1d458b

Browse files
author
fairlix
authored
Added omitted code, changed wording
1 parent a5ee4ca commit b1d458b

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

doc/python/lines-on-maps.md

+46-5
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,43 @@ fig.update_layout(
111111

112112
fig.show()
113113
```
114-
### High performance US Flight Paths Map
115-
If you can relinquish having individual styles for the flight paths (e.g. opacity), you can put multiple paths into one trace, which makes the map render much faster.
114+
### Performance improvement: put many lines in the same trace
115+
For very large amounts (>1000) of lines, performance may become critcal. If you can relinquish setting individual line styles (e.g. opacity), you can put multiple paths into one trace. This makes the map render faster and reduces the script execution time and memory consumption.
116116

117117
Use ```None``` between path coordinates to create a break in the otherwise connected paths.
118118

119119
```python
120-
# ... omitted code: look at the previous "US Flight Paths Map" example
120+
import plotly.graph_objects as go
121+
import pandas as pd
122+
123+
df_airports = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')
124+
df_airports.head()
125+
126+
df_flight_paths = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv')
127+
df_flight_paths.head()
128+
129+
fig = go.Figure()
130+
131+
fig.add_trace(go.Scattergeo(
132+
locationmode = 'USA-states',
133+
lon = df_airports['long'],
134+
lat = df_airports['lat'],
135+
hoverinfo = 'text',
136+
text = df_airports['airport'],
137+
mode = 'markers',
138+
marker = dict(
139+
size = 2,
140+
color = 'rgb(255, 0, 0)',
141+
line = dict(
142+
width = 3,
143+
color = 'rgba(68, 68, 68, 0)'
144+
)
145+
)))
146+
147+
flight_paths = []
121148
lons = []
122149
lats = []
123150
for i in range(len(df_flight_paths)):
124-
# None interrupts lines and makes it possible to draw multiple disconnected lines.
125151
lons += [df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i], None]
126152
lats += [df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i], None]
127153

@@ -135,7 +161,22 @@ fig.add_trace(
135161
opacity = 0.5
136162
)
137163
)
138-
# ... omitted code: look at the previous "US Flight Paths Map" example
164+
165+
fig.update_layout(
166+
title_text = 'Feb. 2011 American Airline flight paths<br>(Hover for airport names)',
167+
showlegend = False,
168+
geo = go.layout.Geo(
169+
scope = 'north america',
170+
projection_type = 'azimuthal equal area',
171+
showland = True,
172+
landcolor = 'rgb(243, 243, 243)',
173+
countrycolor = 'rgb(204, 204, 204)',
174+
),
175+
height=700,
176+
)
177+
178+
fig.show()
179+
139180
```
140181

141182

0 commit comments

Comments
 (0)