Migration from v1 (matplotlib) to v2 (SVG)¶
The import statement is unchanged:
from mappyng import Map
The constructor signature is preserved. The drawing API, however, is now
object-based: instead of m.add_choropleth(gdf, {...}) you build a
layer and add it with m.add(Choropleth(gdf, ...)). The dict-based
add_* helpers have been removed (see Quickstart).
The parameter names below still apply; they are now keyword arguments of
the corresponding layer class.
Layer and element names¶
Layers and chrome are objects added with + or m.add(...) (see
Quickstart). The layer classes lost their Layer
suffix; the former names were removed in mappyng 2.0 (they had emitted a
DeprecationWarning since the layer classes were introduced).
Former |
Current |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m.add(layer) now returns the map instead of the layer; the layer
still receives its id. Vector is drawn in the cartouches by
default (on_cartouches=True), like the thematic layers.
Renamed parameters¶
v1 parameter |
v2 parameter |
Notes |
|---|---|---|
|
|
Proportional and situation layers. |
|
|
Proportional and situation layers. |
|
|
Proportional and situation layers. |
|
|
ProportionalLegendConfig. |
|
|
ProportionalLegendConfig. |
|
|
SVG dasharray string instead of matplotlib line style. |
|
|
ProportionalLegendConfig. |
|
|
ProportionalLegendConfig. |
|
|
Legend label decimal places. |
|
|
Choropleth. |
|
|
Choropleth. |
Removed parameters¶
These v1 parameters are not available in v2:
v1 parameter |
Reason |
|---|---|
|
v2 proportional symbols are always circles. |
|
Z-order is managed globally by |
|
v2 uses |
|
v2 always uses SVG pixel coordinates. |
PNG custom markers ( |
v2 is SVG-native only. Use custom SVG files instead. |
New parameters in v2¶
These parameters are not present in v1:
Parameter |
Method / class |
Description |
|---|---|---|
|
Global font size multiplier. |
|
|
Proportional |
Fixed circle radius in SVG px (replaces |
|
ProportionalLegendConfig |
Number of auto-generated legend values. |
|
ProportionalLegendConfig |
Legend circle fill opacity. |
|
SituationLegendConfig |
Multi-column legend layout. |
|
ChoroplethLegendConfig |
SVG hatch pattern for legend swatches. |
|
|
Hover effect opacity: |
|
ChoroplethLegendConfig (horizontal) |
Label centering and range formatting for horizontal legends. |
Tile basemaps¶
v1 used contextily (matplotlib-based). v2 downloads tiles directly:
# v1
import contextily as cx
cx.add_basemap(ax, source=cx.providers.CartoDB.Positron)
# v2
from mappyng import Tile
m.add(Tile(source="cartodb_positron"))
Requires pip install mappyng[tile].
Label placement¶
v1 used adjustText (matplotlib). v2 uses a pure Python simulated-annealing
implementation with geometric obstacle avoidance:
# v1
m.add_toponyms(gdf, column="nom", max_labels=20)
# v2
from mappyng import Label
m.add(Label(gdf, column="nom", max_labels=20, n_sweeps=50))
Exceptions¶
v2 exposes a typed exception hierarchy not present in v1:
from mappyng.errors import MapError, DataError, RenderError