Visualisers¶
What is the visualiser module?
The visualiser
module is responsible to deliver visualiser's primitives such as matplotlib or folium,
following a UrbanMapper
's analysis.
Meanwhile, we recommend to look through the Example
's Visualiser for a more hands-on introduction about
the Visualiser module and its usage.
Documentation Under Alpha Construction
This documentation is in its early stages and still being developed. The API may therefore change, and some parts might be incomplete or inaccurate.
Use at your own risk, and please report anything that seems incorrect
/ outdated
you find.
VisualiserBase
¶
Bases: ABC
Base class for all visualisers in UrbanMapper
This abstract class defines the common interface that all visualiser implementations
must follow. Visualisers are responsible for creating visual representations following a UrbanMapper
's analysis.
Method Not Implemented
This is an abstract class and cannot be instantiated directly. Use concrete
implementations such as StaticVisualiser
or InteractiveVisualiser
instead.
Attributes:
Name | Type | Description |
---|---|---|
style |
Dict[str, Any]
|
A dictionary of style parameters to apply to the visualisation. The specific style parameters depend on the visualiser implementation. |
Source code in src/urban_mapper/modules/visualiser/abc_visualiser.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
_render(urban_layer_geodataframe, columns, **kwargs)
abstractmethod
¶
Internal implementation method for rendering visualisations.
Called by render()
after validation.
Method Not Implemented
This method must be implemented by subclasses. It should contain the logic for creating the visualisation based on the provided GeoDataFrame and columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urban_layer_geodataframe
|
GeoDataFrame
|
The |
required |
columns
|
List[str]
|
List of column names to include in the visualisation. |
required |
**kwargs
|
Additional implementation-specific parameters. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The visualisation result, which varies by implementation. |
Raises:
Type | Description |
---|---|
ValueError
|
If the visualisation cannot be performed. |
Source code in src/urban_mapper/modules/visualiser/abc_visualiser.py
render(urban_layer_geodataframe, columns, **kwargs)
¶
Render a visualisation of the provided GeoDataFrame
The primary public method for generating visualisations. It validates inputs and
delegates to the subclass-specific _render()
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urban_layer_geodataframe
|
GeoDataFrame
|
The |
required |
columns
|
List[str]
|
List of column names to include in the visualisation.
These columns must exist in the |
required |
**kwargs
|
Additional implementation-specific parameters for customising the visualisation, such as figure size, title, colours, etc. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The visualisation result, which varies by implementation (e.g., a plot, map, figure, or interactive widget). |
Raises:
Type | Description |
---|---|
ValueError
|
If urban_layer_geodataframe lacks a 'geometry' column. |
ValueError
|
If urban_layer_geodataframe is empty. |
ValueError
|
If any specified columns don't exist in urban_layer_geodataframe. |
ValueError
|
If the visualisation cannot be performed. |
Examples:
>>> from urban_mapper.modules.visualiser import InteractiveVisualiser
>>> viz = InteractiveVisualiser(style={"color": "red", "opacity": 0.7})
>>> viz.render(
... urban_layer_geodataframe=enriched_gdf,
... columns=["nearest_street", "distance_to_street"],
... title="Streets Analysis"
... )
Source code in src/urban_mapper/modules/visualiser/abc_visualiser.py
preview(format='ascii')
abstractmethod
¶
Generate a preview of this visualiser.
Provides a summary of the visualiser's configuration for inspection.
Method Not Implemented
This method must be implemented by subclasses. It should return a representation of the visualiser's configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The output format. Options are:
|
'ascii'
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
A representation of the visualiser in the requested format (e.g., str or dict). |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported format is specified. |
Source code in src/urban_mapper/modules/visualiser/abc_visualiser.py
StaticVisualiser
¶
Bases: VisualiserBase
A visualiser that creates static plots using Matplotlib.
This visualiser generates static visualisations of geographic data using Matplotlib. It supports plotting a single column from the GeoDataFrame.
Available Style Options
Common style keys for StaticVisualiser
include:
- figsize
: Figure size as a tuple (width, height).
- cmap
: Colormap for numeric data.
- color
: Colour for non-numeric data.
- markersize
: Size of markers.
- legend
: Whether to show a legend.
- vmin
: Minimum value for color scaling.
- vmax
: Maximum value for color scaling.
Attributes:
Name | Type | Description |
---|---|---|
short_name |
str
|
Short identifier for the visualiser. |
allowed_style_keys |
set
|
Valid style parameters that can be provided. |
style |
dict
|
Style parameters applied to the visualisation. |
Examples:
>>> from urban_mapper.modules.visualiser import StaticVisualiser
>>> viz = StaticVisualiser()
>>> viz.render(
... urban_layer_geodataframe=streets_gdf,
... columns=["street_name"],
... figsize=(10, 8),
... cmap="viridis"
... )
Source code in src/urban_mapper/modules/visualiser/visualisers/static_visualiser.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
_render(urban_layer_geodataframe, columns, **kwargs)
¶
Render a static plot of the GeoDataFrame.
Creates a static Matplotlib plot for the specified column. It renders each source (data_id column) with different markers, when the GeoDataFrame has data_id column
To Keep in Mind
Only supports visualisation of a single column at a time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urban_layer_geodataframe
|
GeoDataFrame
|
The GeoDataFrame to visualise. |
required |
columns
|
List[str]
|
A list with a single column name to plot. |
required |
**kwargs
|
Additional parameters for customising the plot, overriding any style parameters set during initialisation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
A Matplotlib figure object. |
Raises:
Type | Description |
---|---|
ValueError
|
If more than one column is specified. |
Source code in src/urban_mapper/modules/visualiser/visualisers/static_visualiser.py
preview(format='ascii')
¶
Generate a preview of this static visualiser.
Provides a summary of the visualiser's configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The output format ("ascii" or "json"). Defaults to "ascii". |
'ascii'
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
A string (for "ascii") or dict (for "json") representing the visualiser. |
Raises:
Type | Description |
---|---|
ValueError
|
If format is unsupported. |
Examples:
Source code in src/urban_mapper/modules/visualiser/visualisers/static_visualiser.py
InteractiveVisualiser
¶
Bases: VisualiserBase
A visualiser that creates interactive web maps with Folium.
This visualiser generates interactive maps using Folium, allowing for zooming
,
panning
, layer selection
, tooltips
, and popups
. For multiple columns
, it provides
a dropdown
to switch between different data visualisations.
Available Style Options
Common style keys for InteractiveVisualiser
include:
- width
: Width of the map in pixels.
- height
: Height of the map in pixels.
- color
: Colour for non-numeric data.
- opacity
: Transparency level.
- tiles
: Base map tiles (e.g., "OpenStreetMap", "CartoDB positron"). See further in Folium Tiles
- tooltip
: Whether to show tooltips on hover.
- popup
: Whether to show popups on click.
- cmap
: Colormap for numeric data.
- legend
: Whether to show a legend.
- vmin
: Minimum value for color scaling.
- vmax
: Maximum value for color scaling.
- colorbar_text_color
: Text color for the color bar.
Attributes:
Name | Type | Description |
---|---|---|
short_name |
str
|
Short identifier for the visualiser. |
allowed_style_keys |
set
|
Valid style parameters that can be provided. |
style |
dict
|
Style parameters applied to the visualisation. |
Examples:
>>> from urban_mapper.modules.visualiser import InteractiveVisualiser
>>> viz = InteractiveVisualiser()
>>> viz.render(
... urban_layer_geodataframe=streets_gdf,
... columns=["street_name"]
... )
>>> viz = InteractiveVisualiser(style={
... "color": "red",
... "opacity": 0.7,
... "tooltip": True,
... "tiles": "CartoDB positron"
... })
>>> viz.render(
... urban_layer_geodataframe=enriched_gdf,
... columns=["nearest_street", "distance_to_street"],
... legend=True
... )
Source code in src/urban_mapper/modules/visualiser/visualisers/interactive_visualiser.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
_render(urban_layer_geodataframe, columns, **kwargs)
¶
Render an interactive map of the GeoDataFrame.
Creates an interactive Folium map displaying the data. For numeric columns, it creates choropleth maps with color scales. For categorical columns, it creates categorical maps with distinct colors. When multiple columns are provided, it includes a dropdown to switch between them.
To Keep in Mind
Requires an internet connection for map tiles and interactivity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urban_layer_geodataframe
|
GeoDataFrame
|
The GeoDataFrame to visualise. |
required |
columns
|
List[str]
|
List of column names to include in the visualisation. |
required |
**kwargs
|
Additional parameters for customising the visualisation, overriding any style parameters set during initialisation. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
A Folium map object for a single column, or an ipywidgets.VBox for multiple columns. |
Raises:
Type | Description |
---|---|
ValueError
|
If no columns are specified. |
Source code in src/urban_mapper/modules/visualiser/visualisers/interactive_visualiser.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
preview(format='ascii')
¶
Generate a preview of this interactive visualiser.
Provides a summary of the visualiser's configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The output format ("ascii" or "json"). Defaults to "ascii". |
'ascii'
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
A string (for "ascii") or dict (for "json") representing the visualiser. |
Raises:
Type | Description |
---|---|
ValueError
|
If format is unsupported. |
Examples:
>>> viz = InteractiveVisualiser()
>>> print(viz.preview())
Visualiser: InteractiveVisualiser using Folium
Style: Default styling
Source code in src/urban_mapper/modules/visualiser/visualisers/interactive_visualiser.py
VisualiserFactory
¶
Factory class for creating and configuring data visualisers
Provides a fluent chaining-methods-based interface to instantiate visualisers, configure settings, and render visualisations within the UrbanMapper framework.
Attributes:
Name | Type | Description |
---|---|---|
_type |
Optional[str]
|
The type of visualiser to create. |
_style |
Dict[str, Any]
|
Style configuration for the visualiser. |
_columns |
Optional[List[str]]
|
Columns from the data to visualise. |
_instance |
Optional[VisualiserBase]
|
The visualiser instance (internal use). |
_preview |
Optional[dict]
|
Preview configuration (internal use). |
Examples:
>>> from urban_mapper import UrbanMapper
>>> import geopandas as gpd
>>> mapper = UrbanMapper()
>>> neighborhoods = mapper.urban_layer.region_neighborhoods().from_place("Manhattan, New York")
>>> map_viz = mapper.visual.with_type("InteractiveVisualiser") ... .with_style({"width": 800, "height": 600}) ... .show("neighborhood") ... .render(neighborhoods)
Source code in src/urban_mapper/modules/visualiser/visualiser_factory.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
with_type(primitive_type)
¶
Specify the type of visualiser to create.
Sets the type of visualiser, determining the visualisation strategy.
How to find available visualiser types?
To find available visualiser types, you can check the VISUALISER_REGISTRY
dictionary.
Or directly going to the urban_mapper.modules.visualiser.visualisers
directory.
Each visualiser class should have a short_name
attribute that serves as its identifier.
Instead, you simply also can se list(VISUALISER_REGISTRY.keys())
to see available visualiser types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
primitive_type
|
str
|
The name of the visualiser type (e.g., "InteractiveVisualiser"). |
required |
Returns:
Name | Type | Description |
---|---|---|
VisualiserFactory |
VisualiserFactory
|
Self for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If primitive_type is not in VISUALISER_REGISTRY. |
Examples:
Source code in src/urban_mapper/modules/visualiser/visualiser_factory.py
with_style(style)
¶
Set the style options for the visualiser.
Configures style options like colours, width, height, and opacity.
how to know which style options are available?
To know which style options are available, you can check the allowed_style_keys
attribute
in each visualiser class. This attribute contains a set of keys that are accepted for styling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
style
|
Dict[str, Any]
|
A dictionary of style options. |
required |
Returns:
Name | Type | Description |
---|---|---|
VisualiserFactory |
VisualiserFactory
|
Self for method chaining. |
Examples:
>>> visualiser = mapper.visual.with_style({
... "width": 800,
... "height": 600,
... "color": "blue",
... "opacity": 0.7
... })
Source code in src/urban_mapper/modules/visualiser/visualiser_factory.py
show(columns)
¶
Specify which columns from the data should be visualised.
Sets the columns to include in the visualisation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
columns
|
Union[str, List[str]]
|
A single column name or list of column names. |
required |
Returns:
Name | Type | Description |
---|---|---|
VisualiserFactory |
VisualiserFactory
|
Self for method chaining. |
Examples:
>>> visualiser = mapper.visual.show("population")
>>> visualiser = mapper.visual.show(["population", "area"])
Source code in src/urban_mapper/modules/visualiser/visualiser_factory.py
render(urban_layer_geodataframe)
¶
Render the visualisation using the provided data.
Creates and renders a visualiser instance with the configured options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urban_layer_geodataframe
|
GeoDataFrame
|
The |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The visualisation output (e.g., a map widget or figure). |
Raises:
Type | Description |
---|---|
ValueError
|
If _type or _columns are not set, or if invalid style keys are used. |
Examples:
>>> map_viz = VisualiserFactory().with_type("InteractiveVisualiser") ... .show("neighborhood") ... .render(neighborhoods_gdf)
Source code in src/urban_mapper/modules/visualiser/visualiser_factory.py
build()
¶
Build and return the configured visualiser instance.
Creates a visualiser instance for use in pipelines or deferred rendering.
To Keep In Mind
Prefer render()
for immediate visualisation; use build()
for pipelines.
Returns:
Name | Type | Description |
---|---|---|
VisualiserBase |
VisualiserBase
|
A configured visualiser instance. |
Raises:
Type | Description |
---|---|
ValueError
|
If _type is not set. |
Examples:
>>> visualiser = mapper.visual.with_type("StaticVisualiser") ... .with_style({"figsize": (10, 8)}) ... .build()
Source code in src/urban_mapper/modules/visualiser/visualiser_factory.py
preview(format='ascii')
¶
Generate a preview of the configured visualiser.
Shows the visualiser’s configuration in the specified format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The format to display ("ascii" or "json"). Defaults to "ascii". |
'ascii'
|
Raises:
Type | Description |
---|---|
ValueError
|
If format is unsupported. |
Examples:
>>> factory = mappper.visual.with_type("InteractiveVisualiser").build()
>>> factory.preview(format="json")
Source code in src/urban_mapper/modules/visualiser/visualiser_factory.py
with_preview(format='ascii')
¶
Configure the factory to display a preview after building.
Enables automatic preview after build()
or render()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The preview format ("ascii" or "json"). Defaults to "ascii". |
'ascii'
|
Returns:
Name | Type | Description |
---|---|---|
VisualiserFactory |
VisualiserFactory
|
Self for chaining. |
Examples:
>>> visualiser = mapper.visual.with_type("InteractiveVisualiser") ... .with_preview(format="json") ... .build()