Skip to content

Commit 94fa2ce

Browse files
Merge branch 'doc-prod'
2 parents f03e8cc + d1584a4 commit 94fa2ce

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

doc/python/histograms.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fig.show()
8888

8989
#### Type of normalization
9090

91-
The default mode is to represent the count of samples in each bin. With the `histnorm` argument, it is also possible to represent the percentage or fraction of samples in each bin (`histnorm='percent'` or `probability`), or a density histogram (the sum of bars is equal to 100, `density`), or a probability density histogram (sum equal to 1, `probability density`).
91+
The default mode is to represent the count of samples in each bin. With the `histnorm` argument, it is also possible to represent the percentage or fraction of samples in each bin (`histnorm='percent'` or `probability`), or a density histogram (the sum of all bar areas equals the total number of sample points, `density`), or a probability density histogram (the sum of all bar areas equals 1, `probability density`).
9292

9393
```python
9494
import plotly.express as px

doc/python/lines-on-maps.md

+74
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,80 @@ fig.update_layout(
111111

112112
fig.show()
113113
```
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.
116+
117+
Use ```None``` between path coordinates to create a break in the otherwise connected paths.
118+
119+
```python
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 = []
148+
lons = []
149+
lats = []
150+
import numpy as np
151+
lons = np.empty(3 * len(df_flight_paths))
152+
lons[::3] = df_flight_paths['start_lon']
153+
lons[1::3] = df_flight_paths['end_lon']
154+
lons[::3] = None
155+
lats = np.empty(3 * len(df_flight_paths))
156+
lats[::3] = df_flight_paths['start_lat']
157+
lats[1::3] = df_flight_paths['end_lat']
158+
lats[::3] = None
159+
160+
fig.add_trace(
161+
go.Scattergeo(
162+
locationmode = 'USA-states',
163+
lon = lons,
164+
lat = lats,
165+
mode = 'lines',
166+
line = dict(width = 1,color = 'red'),
167+
opacity = 0.5
168+
)
169+
)
170+
171+
fig.update_layout(
172+
title_text = 'Feb. 2011 American Airline flight paths<br>(Hover for airport names)',
173+
showlegend = False,
174+
geo = go.layout.Geo(
175+
scope = 'north america',
176+
projection_type = 'azimuthal equal area',
177+
showland = True,
178+
landcolor = 'rgb(243, 243, 243)',
179+
countrycolor = 'rgb(204, 204, 204)',
180+
),
181+
height=700,
182+
)
183+
184+
fig.show()
185+
186+
```
187+
114188

115189
### London to NYC Great Circle
116190

0 commit comments

Comments
 (0)