Skip to content

Commit 30c9eef

Browse files
author
Nathaniel Henry
committed
Truncate the YlGnBu fill scale to its 10-90% range so extremes are less jarring.
1 parent 9be4bda commit 30c9eef

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

src/closecity/map.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
# Above it (block maps), a single trace keeps rendering fast.
1919
_OVERLAP_MAX = 12
2020

21+
# "YlGnBu" truncated to its 10-90% range — the extreme dark-blue and pale-yellow
22+
# look jarring on the pale basemap. Ordered blue->yellow to match plotly's named
23+
# "YlGnBu" in a trace, so `reverse` behaves the same as before.
24+
_YLGNBU_TRUNC = [
25+
[0.0, "rgb(31, 47, 136)"], [0.125, "rgb(35, 77, 160)"],
26+
[0.25, "rgb(32, 114, 178)"], [0.375, "rgb(36, 152, 193)"],
27+
[0.5, "rgb(65, 182, 196)"], [0.625, "rgb(115, 200, 189)"],
28+
[0.75, "rgb(170, 222, 183)"], [0.875, "rgb(214, 239, 179)"],
29+
[1.0, "rgb(241, 249, 185)"],
30+
]
31+
32+
33+
def _scale(palette):
34+
return _YLGNBU_TRUNC if palette == "YlGnBu" else palette
35+
2136

2237
def _rgba(hexcolor: str, alpha: float) -> str:
2338
h = hexcolor.lstrip("#")
@@ -207,7 +222,7 @@ def close_map(
207222
hoverinfo="skip", showlegend=False,
208223
))
209224
if fv is not None:
210-
marker = {"size": size, "color": fv, "colorscale": palette,
225+
marker = {"size": size, "color": fv, "colorscale": _scale(palette),
211226
"reversescale": reverse, "showscale": True,
212227
"colorbar": {"title": fill}}
213228
else:
@@ -241,7 +256,7 @@ def close_map(
241256
featureidkey="properties._id", z=[fv[i]], coloraxis="coloraxis",
242257
marker={"opacity": opacity, "line": poly_line},
243258
text=[hover[i]], hoverinfo="text", showlegend=False))
244-
coloraxis = {"colorscale": palette, "reversescale": reverse,
259+
coloraxis = {"colorscale": _scale(palette), "reversescale": reverse,
245260
"cmin": min(fv), "cmax": max(fv), "colorbar": {"title": fill}}
246261
else:
247262
geojson = json.loads(g[["_id", "geometry"]].to_json())
@@ -253,7 +268,7 @@ def close_map(
253268
}
254269
if fv is not None:
255270
traces.append(go.Choroplethmapbox(
256-
z=fv, colorscale=palette, reversescale=reverse,
271+
z=fv, colorscale=_scale(palette), reversescale=reverse,
257272
showscale=True, colorbar={"title": fill}, **common))
258273
else:
259274
z = [1] * len(g) if hl is None else [int(h) for h in hl]

0 commit comments

Comments
 (0)