Layout Elements¶
Title, scale bar, source attribution and north arrow are chrome
elements: Title, ScaleBar,
Source and NorthArrow. Cartouches
(Insets) and the zoom window (Zoom)
are elements too. All are added like layers, with + or
add(). Chrome is drawn when the map is rendered;
adding a second title replaces the first.
The methods m.title(...), m.scale_bar(...), m.source(...),
m.north_arrow(...), m.add_zoom({...}) and m.add_shadow(...)
remain as shortcuts for the matching element.
Title¶
The first argument is the title text; the rest are keyword options.
m = m + mp.Title(
"Population par département",
subtitle="Source : INSEE, 2024",
loc="left",
font_size=14,
font_weight="bold",
top_gap=10,
offset_x=0,
offset_y=0,
)
Key |
Default |
Description |
|---|---|---|
|
required |
Title text. Wrapped automatically at |
|
|
Subtitle rendered below the title. |
|
|
Horizontal alignment: |
|
60 |
Maximum characters per line before wrapping. |
|
from style |
Title font size (scaled by |
|
from style |
Title color. |
|
from style |
Font weight (e.g. |
|
from style |
Font family. |
|
auto |
Subtitle font size (defaults to |
|
from style |
Subtitle color. |
|
|
Subtitle font weight. |
|
8 |
Gap between title baseline and map top edge (SVG px). Positive = title moves up. |
|
|
Place the title anywhere instead of above the map (anchor: baseline
of the last line, aligned by |
|
0.0 |
Additional horizontal shift (SVG px). |
|
0.0 |
Additional vertical shift (SVG px). |
Scale bar¶
mp.ScaleBar() # fully automatic
mp.ScaleBar(length=200_000, label="200 km")
mp.ScaleBar(location="lower left", color="#444444",
bar_height=4, opacity=0.8)
mp.ScaleBar(position=(0.46, 0.9)) # fractions of the content
Key |
Default |
Description |
|---|---|---|
|
auto |
Bar length in map CRS units. Auto: ~20 % of map width. |
|
auto |
Label text. Auto-generated from |
|
|
Unit string appended to auto-label. |
|
1000 |
Divisor for CRS-units to display-units (default: metres to km). |
|
|
Preset position: |
|
|
Manual position of the left end of the bar (overrides
|
|
from style |
Unified color for bar, ticks, and label. |
|
from |
Bar line color override. |
|
from |
Tick color override. |
|
from |
Label color override. |
|
8 |
Label font size. |
|
|
Label font weight. |
|
from style |
Label font family. |
|
3 |
Bar line thickness (SVG px). |
|
|
Tick mark height (SVG px). |
|
1 |
Tick stroke width (SVG px). |
|
15 |
Distance from the content edge to the bar (SVG px). |
|
1.0 |
Overall opacity 0-1. |
Source attribution¶
mp.Source("Source : INSEE")
mp.Source("Source : INSEE\\nTraitement : auteur", layout="horizontal")
mp.Source("Source : IGN, GéoFLA", position=(0.5, 1.05))
Key |
Default |
Description |
|---|---|---|
|
required |
Attribution text. Use |
|
|
|
|
|
Manual position of the start of the text (overrides |
|
90 / 0 |
Explicit rotation in degrees (default depends on layout). |
|
from style |
Font size. |
|
from style |
Text color. |
|
from style |
Text opacity. |
|
|
CSS font-style. |
|
|
CSS font-weight. |
|
from style |
Font family. |
|
auto |
SVG text-anchor: |
Placing elements and finer zoom geometry¶
Every element with a position accepts fractions, percentages, pixels and
geographic coordinates: see Placing elements. The zoom window and the
cartouches can draw a finer geometry than the main map while keeping the
layer’s symbology: see Finer geometry in zooms and cartouches.
Cartouches (Insets)¶
Cartouches show areas away from the main frame (overseas territories,
Alaska…), each in its own CRS, stacked on the left of the map. An
Insets groups them; options passed to Insets apply
to every Inset that does not set them.
insets = mp.Insets(
[
mp.Inset("Guadeloupe", bbox=[-6890454, 1780151, -6799589, 1874186],
crs=3857),
mp.Inset("Martinique", bbox=[-6826862, 1609607, -6759494, 1685367],
crs=3857),
],
spacing=15, title_size=7, border_radius=6, box_shadow=True,
)
m = m + insets
Layers are drawn in the cartouches by default. Pass
on_cartouches=False to keep a layer on the main map only.
Option |
Default |
Description |
|---|---|---|
|
|
Title above the cartouche (first argument of |
|
required |
Area shown and its CRS. |
|
8 |
Title font size. |
|
1.0 |
Scale factor of the cartouche. |
|
auto |
Space above the cartouche (SVG px). On |
|
from style |
Frame of the cartouche. |
|
|
Effects, same format as on the main map. |
Zoom window (Zoom)¶
m = m + mp.Zoom([586377, 6780533, 739396, 6904563],
border_radius=8, box_shadow=True)
Thematic layers are redrawn in the zoom window by default
(on_zoom=True); vector layers and drop shadows are not.
In a YAML document, the zoom window is a top-level zoom block with
the same keys:
zoom:
bbox: [586377, 6780533, 739396, 6904563]
border_radius: 8
box_shadow: true
Key |
Default |
Description |
|---|---|---|
|
required |
Geographic bounding box |
|
auto |
SVG pixel position of the zoom window top-left corner. |
|
auto |
Zoom window size in SVG px. |
|
from style |
Border stroke color. |
|
1 |
Border stroke width (SVG px). |
|
4 |
Corner radius (SVG px, 0 = sharp). |
|
|
Drop shadow: |
|
|
Outer glow: same format as |
Ocean gradient (OceanGradient)¶
An optional gradient on the ocean, fading out from the coastline of a layer. With the default white colour it lightens the water along the coast; a dark colour gives the opposite effect.
m = (
mp.Map(europe, bbox=bbox_metro, facecolor="#B9D9EB")
+ mp.OceanGradient(europe)
+ mp.Basemap()
)
It is drawn above the facecolor and below every other layer,
whatever the order in which it is added. The gradient is made of nested
buffers of the dissolved geometries rather than an SVG filter, so PNG and
PDF exports match the SVG.
Key |
Default |
Description |
|---|---|---|
|
|
pandas query selecting the rows the gradient starts from. |
|
24 |
Distance in pixels over which the gradient fades out. |
|
|
Gradient colour along the coast. |
|
0.45 |
Opacity along the coast; it decreases to 0 at |
|
8 |
Number of bands. More bands give a smoother gradient and a larger file. |
|
|
Draw in the cartouches and in the zoom window. |
Graticule (Graticule)¶
m = m + mp.Graticule(step=5.0, stroke="#888888", opacity=0.4,
stroke_width=0.5, dash="4 2")
Key |
Default |
Description |
|---|---|---|
|
10.0 |
Graticule spacing in degrees. |
|
|
Line color. |
|
0.5 |
Line opacity. |
|
0.5 |
Line width (SVG px). |
|
|
SVG |