Skip to content

Commit 7351db6

Browse files
authored
Merge pull request #301 from statisticsnorway/map-hatches
strip gs://
2 parents 21b18e8 + 2633f9a commit 7351db6

File tree

7 files changed

+226
-189
lines changed

7 files changed

+226
-189
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,13 @@ weights["weight"] = 10
126126
frequencies = nwa.get_route_frequencies(origins, destinations, weight_df=weights)
127127

128128
# plot the results
129-
m = sg.ThematicMap(sg.buff(frequencies, 15), column="frequency", black=True)
130-
m.cmap = "plasma"
131-
m.title = "Number of times each road was used,\nweighted * 10"
129+
m = sg.ThematicMap(
130+
sg.buff(frequencies, 15),
131+
column="frequency",
132+
black=True,
133+
cmap="plasma",
134+
title="Number of times each road was used,\nweighted * 10",
135+
)
132136
m.plot()
133137
```
134138

@@ -143,9 +147,14 @@ service_areas = nwa.service_area(
143147
)
144148

145149
# plot the results
146-
m = sg.ThematicMap(service_areas, column="minutes", black=True, size=10)
147-
m.k = 10
148-
m.title = "Roads that can be reached within 1 to 10 minutes"
150+
m = sg.ThematicMap(
151+
service_areas,
152+
column="minutes",
153+
black=True,
154+
size=10,
155+
k=10,
156+
title="Roads that can be reached within 1 to 10 minutes",
157+
)
149158
m.plot()
150159
```
151160

@@ -158,9 +167,15 @@ routes = nwa.get_k_routes(
158167
points.iloc[[0]], points.iloc[[1]], k=4, drop_middle_percent=50
159168
)
160169

161-
m = sg.ThematicMap(sg.buff(routes, 15), column="k", black=True)
162-
m.title = "Four fastest routes from A to B"
163-
m.legend.title = "Rank"
170+
m = sg.ThematicMap(
171+
sg.buff(routes, 15),
172+
column="k",
173+
black=True,
174+
title="Four fastest routes from A to B",
175+
legend_kwargs=dict(
176+
title="Rank",
177+
),
178+
)
164179
m.plot()
165180
```
166181

docs/examples/maps.md

Lines changed: 90 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
# Maps
22

33
```python
4-
import os
5-
import warnings
6-
7-
import numpy as np
8-
import pandas as pd
9-
10-
11-
os.chdir("../../src")
12-
134
import sgis as sg
14-
15-
16-
# ignore some warnings
17-
pd.options.mode.chained_assignment = None
18-
warnings.filterwarnings(action="ignore", category=FutureWarning)
195
```
206

217
First get 1000 addresses in Oslo and create a distance to neighbors column.
@@ -55,8 +41,11 @@ print(points)
5541
Create and save a simple plot with legend and title.
5642

5743
```python
58-
m = sg.ThematicMap(sg.buff(points, 100), column="mean_dist_99_neighbors")
59-
m.title = "Distance to 99 nearest neighbors"
44+
m = sg.ThematicMap(
45+
sg.buff(points, 100),
46+
column="mean_dist_99_neighbors",
47+
title="Distance to 99 nearest neighbors",
48+
)
6049
m.plot()
6150
m.save("path_to_file.png")
6251
```
@@ -66,16 +55,16 @@ m.save("path_to_file.png")
6655
Customising the colors and text. Creating an ugly example.
6756

6857
```python
69-
m = sg.ThematicMap(sg.buff(points, 100), column="mean_dist_99_neighbors")
70-
71-
m.title = "Map with custom (and ugly) colors."
72-
m.title_fontsize = 15
73-
m.title_color = "red"
74-
75-
m.facecolor = "#edf0c9" # background color
76-
77-
m.change_cmap("PuBuGn", start=20, stop=250) # start and stop goes from 0 to 256
78-
58+
m = sg.ThematicMap(
59+
sg.buff(points, 100),
60+
column="mean_dist_99_neighbors",
61+
title="Map with custom (and ugly) colors.",
62+
title_fontsize=15,
63+
title_color="red",
64+
facecolor="#edf0c9", # background color
65+
cmap="PuBuGn",
66+
cmap_start=20,
67+
)
7968
m.plot()
8069
```
8170

@@ -86,16 +75,19 @@ See here for available cmaps: https://matplotlib.org/stable/tutorials/colors/col
8675
Customising the legend can be done through the legend attribute.
8776

8877
```python
89-
m = sg.ThematicMap(sg.buff(points, 100), column="mean_dist_99_neighbors")
90-
91-
m.title = "Map with customised legend"
92-
93-
m.legend.title = "Meters"
94-
m.legend.label_sep = "to"
95-
m.legend.label_suffix = "m"
96-
m.legend.position = (0.35, 0.28)
97-
m.legend.rounding = 1
98-
78+
m = sg.ThematicMap(
79+
sg.buff(points, 100),
80+
column="mean_dist_99_neighbors",
81+
title="Map with customised legend",
82+
legend_kwargs=dict(
83+
title="Meters",
84+
label_sep="to",
85+
label_suffix="m",
86+
position=(0.35, 0.28),
87+
rounding=1,
88+
pretty_labels=True,
89+
),
90+
)
9991
m.plot()
10092
```
10193

@@ -104,23 +96,21 @@ m.plot()
10496
Using custom breaks and labels for the color classification.
10597

10698
```python
107-
m = sg.ThematicMap(sg.buff(points, 100), column="mean_dist_99_neighbors")
108-
109-
m.title = "Map with custom bins and legend labels"
110-
m.legend.title = "Custom labels"
111-
112-
m.bins = [1500, 2000, 2500, 3000]
113-
114-
min_value = points.mean_dist_99_neighbors.min()
115-
max_value = points.mean_dist_99_neighbors.max()
99+
m = sg.ThematicMap(
100+
sg.buff(points, 100),
101+
column="mean_dist_99_neighbors",
102+
title="Map with custom bins",
103+
bins=[1500, 2000, 2500, 3000],
104+
)
105+
min_value = points["mean_dist_99_neighbors"].min()
106+
max_value = points["mean_dist_99_neighbors"].max()
116107
m.legend.labels = [
117108
f"{int(round(min_value))} to 1499",
118109
"1500 to 1999",
119110
"2000 to 2499",
120111
"2500 to 2999",
121112
f"3000 to {int(round(max_value))}",
122113
]
123-
124114
m.plot()
125115
```
126116

@@ -131,10 +121,15 @@ maximum values in each color group. This will be accurate and truthful, but
131121
somewhat confusing.
132122

133123
```python
134-
m = sg.ThematicMap(sg.buff(points, 100), column="mean_dist_99_neighbors")
135-
m.title = "Map with custom bins, but default legend labels"
136-
m.bins = [1500, 2000, 2500, 3000]
137-
m.legend.title = "Default legend labels"
124+
m = sg.ThematicMap(
125+
sg.buff(points, 100),
126+
column="mean_dist_99_neighbors",
127+
title = "Map with custom bins, but default legend labels",
128+
bins = [1500, 2000, 2500, 3000],
129+
legend_kwargs={
130+
"title": "Default legend labels",
131+
},
132+
)
138133
m.plot()
139134
```
140135

@@ -145,14 +140,16 @@ The background gdf will be gray by default, but can be changed by setting
145140
the color.
146141

147142
```python
148-
m = sg.ThematicMap(sg.buff(points, 100), column="mean_dist_99_neighbors")
149-
150-
m.title = "Map with a background GeoDataFrame"
151-
m.legend.title = "Meters"
152-
143+
m = sg.ThematicMap(
144+
sg.buff(points, 100),
145+
column="mean_dist_99_neighbors",
146+
title = "Map with a background GeoDataFrame",
147+
legend_kwargs={
148+
"title": "Meters",
149+
},
150+
)
153151
background = sg.buff(points, 500)
154152
m.add_background(background, color=None)
155-
156153
m.plot()
157154
```
158155

@@ -162,14 +159,17 @@ Setting black to True gives opposite colors and a palette suited for a black
162159
background (viridis).
163160

164161
```python
165-
m = sg.ThematicMap(points, column="mean_dist_99_neighbors", black=True)
166-
167-
m.title = "black=True, with background GeoDataFrame"
168-
m.legend.title = "Meters"
169-
162+
m = sg.ThematicMap(
163+
points,
164+
column="mean_dist_99_neighbors",
165+
black=True,
166+
title = "black=True, with background GeoDataFrame",
167+
legend_kwargs={
168+
"title": "Meters",
169+
},
170+
)
170171
background = sg.buff(points, 500)
171172
m.add_background(background)
172-
173173
m.plot()
174174
```
175175

@@ -178,33 +178,34 @@ m.plot()
178178
Customising all at once.
179179

180180
```python
181-
m = sg.ThematicMap(sg.buff(points, 100), column="mean_dist_99_neighbors")
182-
183-
m.title = "Everything customised"
184-
185-
m.facecolor = "#fcfcfc" # =almost white
186-
m.change_cmap("YlGnBu", start=50, stop=256) # start and stop goes from 0 to 256
187-
188-
m.title_fontsize = 125
189-
m.title_color = "#141414" # =almost black
190-
191-
m.legend.title = "Meters"
192-
m.legend.title_fontsize = 55
193-
m.legend.fontsize = 45
194-
m.legend.markersize = 30
195-
m.legend.position = (0.35, 0.28)
196-
197-
m.bins = [1500, 2000, 2500, 3000]
198-
199-
min_value = points.mean_dist_99_neighbors.min()
200-
max_value = points.mean_dist_99_neighbors.max()
201-
m.legend.labels = [
202-
f"{int(round(min_value))} to 1499",
203-
"1500 to 1999",
204-
"2000 to 2499",
205-
"2500 to 2999",
206-
f"3000 to {int(round(max_value))}",
207-
]
181+
min_value = points["mean_dist_99_neighbors"].min()
182+
max_value = points["mean_dist_99_neighbors"].max()
183+
184+
m = sg.ThematicMap(
185+
sg.buff(points, 100),
186+
column="mean_dist_99_neighbors",
187+
title="Everything customised",
188+
bins=[1500, 2000, 2500, 3000],
189+
facecolor="#fcfcfc", # =almost white
190+
cmap="YlGnBu",
191+
cmap_start=50,
192+
title_fontsize=125,
193+
title_color="#141414", # =almost black
194+
legend_kwargs=dict(
195+
title="Meters",
196+
title_fontsize=55,
197+
fontsize=45,
198+
markersize=30,
199+
position=(0.35, 0.28),
200+
labels=[
201+
f"{int(round(min_value))} to 1499",
202+
"1500 to 1999",
203+
"2000 to 2499",
204+
"2500 to 2999",
205+
f"3000 to {int(round(max_value))}",
206+
],
207+
),
208+
)
208209

209210
background = sg.buff(points, 500)
210211
m.add_background(background, color="#f0f0f0")

0 commit comments

Comments
 (0)