Plotting Functions¶
The georeader.plot module provides matplotlib visualization functions for working with geospatial data, particularly with GeoTensor objects. These functions build on matplotlib to provide convenient ways to visualize raster data with appropriate geographic context.
plot.show¶
This function displays geospatial data on a matplotlib axis. It's a wrapper around matplotlib's imshow function that handles GeoData objects properly, respecting their coordinate systems.
Features: * Automatically handles the extent based on the data's bounds * Optional colorbar display * Optional scale bar showing geographic scale * Can display coordinates in lat/long format * Handles masking of no-data values
Example:
import matplotlib.pyplot as plt
from georeader import plot
# Display RGB data (3-band image)
rgb = (s2img[[3,2,1]] / 3_500).clip(0,1)
plot.show(rgb)

# With colorbar
greyimg = np.mean(rgb, axis=0)
plot.show(greyimg, add_colorbar_next_to=True)

plot.plot_segmentation_mask¶
This function visualizes discrete segmentation masks (like land cover classifications) with appropriate colors and legend.
Features: * Customizable color mapping for different classes * Optional legend with class names * Works with both numeric and categorical data
Example:
# Create a land/water/cloud mask
water = mndwi < 0
land_water_clouds = GeoTensor(np.ones(clouds.shape, dtype=np.uint8),
fill_value_default=0,
crs=clouds.crs,
transform=clouds.transform)
land_water_clouds[water] = 2
land_water_clouds[clouds] = 3
land_water_clouds[invalids] = 0
plot.plot_segmentation_mask(land_water_clouds,
interpretation_array=["invalids","clear","water","cloud"],
color_array=["#000000","#c66d43","#437cc6","#eeeeee"])

plot.add_shape_to_plot¶
This function adds vector data (like points, lines, polygons) to an existing map.
Features: * Works with GeoDataFrame, individual geometries, or lists of geometries * Handles coordinate system transformations * Customizable styling options * Can plot polygon outlines only
Example:
from georeader import plot
from shapely.geometry import box
# Create a plot with raster data
ax = plot.show(rgb)
bbox = box(45.43, -19.53, 45.45, -19.58)
plot.add_shape_to_plot(bbox, ax=ax, polygon_no_fill=True,
crs_plot=rgb.crs,
crs_shape="EPSG:4326",
kwargs_geopandas_plot={"color": "red"})
API Reference¶
show(data, add_colorbar_next_to=False, add_scalebar=False, kwargs_scalebar=None, mask=False, bounds_in_latlng=True, **kwargs)
¶
Wrapper around rasterio.plot.show for GeoData objects. It adds options to add a colorbar next to the plot and a scalebar showing the geographic scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GeoData
|
GeoData object to plot with imshow |
required |
add_colorbar_next_to
|
bool
|
Defaults to False. Add a colorbar next to the plot |
False
|
add_scalebar
|
bool
|
Defaults to False. Add a scalebar to the plot |
False
|
kwargs_scalebar
|
Optional[dict]
|
Defaults to None. Keyword arguments for the scalebar. |
None
|
See
|
https
|
//github.com/ppinard/matplotlib-scalebar. (install with pip install matplotlib-scalebar) |
required |
mask
|
Union[bool, array]
|
Defaults to False. Mask to apply to the data. If True, the fill_value_default of the GeoData is used. |
False
|
bounds_in_latlng
|
bool
|
Defaults to True. If True, the x and y ticks are shown in latlng. |
True
|
**kwargs
|
Keyword arguments for imshow |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
plt.Axes: image object |
Source code in georeader/plot.py
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 | |
plot_segmentation_mask(mask, color_array=None, interpretation_array=None, legend=True, ax=None, add_scalebar=False, kwargs_scalebar=None, min_val_mask=None, max_val_mask=None, bounds_in_latlng=True)
¶
Plots a discrete segmentation mask with a legend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
GeoData
|
(H, W) np.array with values from 0 to len(color_array)-1 |
required |
color_array
|
Optional[NDArray]
|
colors for values 0,...,len(color_array)-1 of mask |
None
|
interpretation_array
|
Optional[List[str]]
|
interpretation for classes 0, ..., len(color_array)-1 |
None
|
legend
|
bool
|
plot the legend |
True
|
ax
|
Optional[Axes]
|
plt.Axes to plot |
None
|
add_scalebar
|
bool
|
Defaults to False. Add a scalebar to the plot |
False
|
kwargs_scalebar
|
Optional[dict]
|
Defaults to None. Keyword arguments for the scalebar. |
None
|
See
|
https
|
//github.com/ppinard/matplotlib-scalebar. (install with pip install matplotlib-scalebar) |
required |
bounds_in_latlng
|
bool
|
Defaults to True. If True, the x and y ticks are shown in latlng. |
True
|
Returns:
| Type | Description |
|---|---|
Axes
|
plt.Axes |
Source code in georeader/plot.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
add_shape_to_plot(shape, ax=None, crs_plot=None, crs_shape=None, polygon_no_fill=False, kwargs_geopandas_plot=None, title=None)
¶
Adds a shape to a plot. It uses geopandas.plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Union[GeoDataFrame, List[BaseGeometry], BaseGeometry]
|
geodata to plot |
required |
ax
|
Optional[Axes]
|
Defaults to None. Axes to plot the shape |
None
|
crs_plot
|
Optional[Any]
|
Defaults to None. crs to plot the shape. If None, the crs of the shape is used. |
None
|
crs_shape
|
Optional[Any]
|
Defaults to None. crs of the shape. If None, the crs of the plot is used. |
None
|
polygon_no_fill
|
bool
|
If True, the polygons are plotted without fill. |
False
|
kwargs_geopandas_plot
|
Optional[Any]
|
Defaults to None. Keyword arguments for geopandas.plot |
None
|
title
|
Optional[str]
|
Defaults to None. Title of the plot. |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
plt.Axes: |
Source code in georeader/plot.py
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 | |