BasemapChart
Coastlines, land, borders, lakes, rivers and roads under a chart of longitude and latitude. The Basemap Chart guide shows every feature on real data; this page is the contract: the function, the shape of its data, the keys style takes, and the constant each parameter accepts.
Function
datachart.charts.BasemapChart
BasemapChart(
data: BASEMAP_FEATURE | str | list[str] | None = None,
*,
resolution: BASEMAP_RESOLUTION | str | None = None,
highlight: str | list[str] | None = None,
geometry: (
BasemapDataAttrs | list[BasemapDataAttrs] | None
) = None,
position: DRAW_POSITION | str | None = None,
title: str | None = None,
xlabel: str | None = None,
ylabel: str | None = None,
figsize: FIG_SIZE | tuple[float, float] | None = None,
xmin: int | float | None = None,
xmax: int | float | None = None,
ymin: int | float | None = None,
ymax: int | float | None = None,
show_grid: SHOW_GRID | str | bool | None = None,
aspect_ratio: ASPECT_RATIO | str | None = None,
style: BasemapStyleAttrs | None = None
) -> DatachartFigure
Creates the basemap chart.
A basemap chart draws the land under a geographic chart: coastlines, a
land fill, the borders between countries, the large lakes, the rivers
and the main roads, from the Natural Earth outlines. Each is downloaded
the first time it is drawn and kept in a local cache, so a map needs the
network once and no extra dependency. Longitude runs along x and latitude
along y, drawn straight; nothing is projected, so the marks composed
over the map with Panel need no transform either — a hexbin of
epicentres, a scatter of stations, a line of a ship's track.
The map carries no series: it takes no cycle color, no legend entry and
no emphasis, and its greys come from the theme. With the countries
feature, highlight picks countries out by their three-letter code: the
ones listed take the highlight color, the rest stay the land's grey. position decides where
it sits in the draw order, under the gridlines and every mark by
default. Composed with other charts it leaves the axis limits to their
data; alone it frames its own outlines. Panel refuses to compose it
with a chart that has categories or dates on an axis, or is horizontal,
since that chart has no longitude to draw the map at. aspect_ratio="geographic"
narrows each degree of longitude by the cosine of the middle latitude,
so a region keeps its proportions.
The default 1:110m outlines suit a continent or a region; resolution
asks for the finer Natural Earth scales, for a country or a coast. The
roads exist at 1:10m alone, and a 1:110m river is only a few strokes
across a continent. geometry takes your own longitude
and latitude outlines in their place: a country's provinces, a coast at
street scale, or a map that is not of the Earth.
Examples:
>>> from datachart.charts import BasemapChart, ScatterChart
>>> from datachart.constants import ASPECT_RATIO, BASEMAP_FEATURE
>>> from datachart.utils import Panel
>>> figure = Panel(
... [
... BasemapChart([BASEMAP_FEATURE.LAND, BASEMAP_FEATURE.BORDERS]),
... ScatterChart([{"x": 14.5, "y": 46.1}, {"x": 16.4, "y": 48.2}]),
... ],
... title="Two capitals",
... xmin=5,
... xmax=25,
... ymin=40,
... ymax=52,
... aspect_ratio=ASPECT_RATIO.GEOGRAPHIC,
... )
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The features to draw: one name or a list of them,
coastline and land by default. See
TYPE:
|
resolution
|
The Natural Earth scale:
TYPE:
|
highlight
|
The countries to pick out, as Natural Earth's three-letter
TYPE:
|
geometry
|
Your own outlines, drawn in place of Natural Earth's: a
TYPE:
|
position
|
Where the map sits in the draw order:
TYPE:
|
title
|
The title of the chart.
TYPE:
|
xlabel
|
The label of the x-axis.
TYPE:
|
ylabel
|
The label of the y-axis.
TYPE:
|
figsize
|
The size of the figure as (width, height) in inches. See
TYPE:
|
xmin
|
The minimum value of the x-axis.
TYPE:
|
xmax
|
The maximum value of the x-axis.
TYPE:
|
ymin
|
The minimum value of the y-axis.
TYPE:
|
ymax
|
The maximum value of the y-axis.
TYPE:
|
show_grid
|
Which grid lines to show ("both", "x", "y");
TYPE:
|
aspect_ratio
|
The aspect ratio of the axes box;
TYPE:
|
style
|
Style configuration of the map. See
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DatachartFigure
|
The figure containing the basemap chart. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a feature is not a |
RuntimeError
|
If a feature is not cached and cannot be downloaded. |
Data
Each record in geometry is a BasemapDataAttrs.
datachart.typings.BasemapDataAttrs
Bases: TypedDict
The geometry attributes for the basemap chart.
| ATTRIBUTE | DESCRIPTION |
|---|---|
lon |
The longitudes of the outlines, drawn on the x-axis. A
TYPE:
|
lat |
The latitudes of the outlines, drawn on the y-axis; as long as
TYPE:
|
feature |
How the outlines are drawn and styled:
TYPE:
|
Style
style takes the keys of BasemapStyleAttrs. Every key falls back to the theme, so the same keys set the default look through config.
datachart.typings.BasemapStyleAttrs
Bases: TypedDict
The typing for the basemap chart style.
| ATTRIBUTE | DESCRIPTION |
|---|---|
plot_basemap_land_color |
The fill color of the land, and of the countries
TYPE:
|
plot_basemap_highlight_color |
The fill color of the countries
TYPE:
|
plot_basemap_highlight_edge_color |
The color of the outline around the countries
TYPE:
|
plot_basemap_highlight_edge_width |
The width of that outline, in points; 0 (default) draws none.
TYPE:
|
plot_basemap_coastline_color |
The color of the coastlines.
TYPE:
|
plot_basemap_coastline_width |
The width of the coastlines, in points.
TYPE:
|
plot_basemap_border_color |
The color of the borders between countries.
TYPE:
|
plot_basemap_border_width |
The width of the borders, in points.
TYPE:
|
plot_basemap_border_style |
The line style of the borders. See
TYPE:
|
plot_basemap_lake_color |
The fill color of the lakes;
TYPE:
|
plot_basemap_river_color |
The color of the rivers.
TYPE:
|
plot_basemap_river_width |
The width of the rivers, in points.
TYPE:
|
plot_basemap_road_color |
The color of the roads.
TYPE:
|
plot_basemap_road_width |
The width of the roads, in points.
TYPE:
|
Constants
The parameters that accept a constant, with the class in datachart.constants that lists its values.
| Parameter | Constant |
|---|---|
data |
BASEMAP_FEATURE |
resolution |
BASEMAP_RESOLUTION |
position |
DRAW_POSITION |
figsize |
FIG_SIZE |
show_grid |
SHOW_GRID |
aspect_ratio |
ASPECT_RATIO |
Composition
Whether the figure composes with each composition function.
| Function | Composes |
|---|---|
Grid |
yes |
Panel |
yes |