Skip to content

Commit dba5f4e

Browse files
authored
Add choropleth support to GeoAxes (#623)
* Add choropleth support to GeoAxes * Use rc defaults for choropleth * Move to docstring snippet manager * Spelling error * Overlay choropleth edges above borders
1 parent 5136aa8 commit dba5f4e

5 files changed

Lines changed: 682 additions & 1 deletion

File tree

docs/examples/geo/04_choropleth.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Simple choropleth
3+
=================
4+
5+
Color country-level values directly on a geographic axes.
6+
7+
Why UltraPlot here?
8+
-------------------
9+
UltraPlot now exposes :meth:`~ultraplot.axes.GeoAxes.choropleth`, so you can
10+
draw country-level thematic maps from plain ISO-style identifiers while using
11+
the same concise colorbar and formatting API used elsewhere in the library.
12+
13+
Key functions: :py:func:`ultraplot.subplots`, :py:meth:`ultraplot.axes.GeoAxes.choropleth`.
14+
15+
See also
16+
--------
17+
* :doc:`Geographic projections </projections>`
18+
"""
19+
20+
import numpy as np
21+
22+
import ultraplot as uplt
23+
24+
country_values = {
25+
"AUS": 1.2,
26+
"BRA": 2.6,
27+
"IND": 3.4,
28+
"ZAF": np.nan,
29+
}
30+
31+
fig, ax = uplt.subplots(proj="robin", refwidth=4.6)
32+
33+
ax.choropleth(
34+
country_values,
35+
country=True,
36+
cmap="Fire",
37+
edgecolor="white",
38+
linewidth=0.6,
39+
colorbar="r",
40+
colorbar_kw={"label": "Index value"},
41+
missing_kw={"facecolor": "gray8", "hatch": "//", "edgecolor": "white"},
42+
)
43+
44+
ax.format(
45+
title="Country choropleth",
46+
ocean=True,
47+
oceancolor="ocean blue",
48+
coast=True,
49+
borders=True,
50+
lonlines=60,
51+
latlines=30,
52+
labels=False,
53+
)
54+
55+
fig.show()

docs/projections.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,35 @@
325325
)
326326

327327

328+
# %%
329+
import shapely.geometry as sgeom
330+
331+
fig, ax = uplt.subplots(proj="cyl", refwidth=3.5)
332+
ax.choropleth(
333+
[
334+
sgeom.box(-20, -10, -5, 5),
335+
sgeom.box(0, -5, 15, 10),
336+
sgeom.box(20, -8, 35, 8),
337+
],
338+
[1.2, 2.4, 0.7],
339+
cmap="Blues",
340+
edgecolor="white",
341+
linewidth=0.8,
342+
colorbar="r",
343+
colorbar_kw={"label": "value"},
344+
)
345+
ax.format(
346+
title="Polygon choropleth",
347+
land=True,
348+
coast=True,
349+
lonlim=(-30, 40),
350+
latlim=(-20, 20),
351+
labels=True,
352+
lonlines=10,
353+
latlines=10,
354+
)
355+
356+
328357
# %% [raw] raw_mimetype="text/restructuredtext"
329358
# .. _ug_geoformat:
330359
#

0 commit comments

Comments
 (0)