Plot Module¶
sensingpy.plot provides visualization utilities for displaying geospatial
data with cartographic projections, custom styling, and RGB composites.
get_projection¶
get_projection
¶
Obtain cartopy projection from a CRS object for plotting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crs
|
CRS
|
Custom object containing coordinate reference system data |
required |
Returns:
| Type | Description |
|---|---|
Projection
|
Cartopy projection object suitable for plotting |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the CRS object is not valid or not supported |
Notes
Currently supports UTM projections explicitly. Defaults to Mercator for other projection types.
Source code in sensingpy/plot.py
get_geofigure¶
get_geofigure
¶
get_geofigure(crs: CRS, nrows: int, ncols: int, figsize: tuple = (12, 6), **kwargs) -> Tuple[Figure, Axes | List[Axes]]
Generate matplotlib figure and axes with georeferenced projections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crs
|
CRS
|
Coordinate reference system for the plot |
required |
nrows
|
int
|
Number of rows for the subplots |
required |
ncols
|
int
|
Number of columns for the subplots |
required |
figsize
|
tuple
|
Dimensions in inches of the figure, by default (12, 6) |
(12, 6)
|
**kwargs
|
Additional keyword arguments passed to plt.subplots() |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[Figure, Axes | List[Axes]]
|
Figure object and either a single Axes object (if nrows=ncols=1) or a list of Axes objects |
Notes
Creates a figure with axes that use the appropriate cartopy projection based on the provided CRS.
Source code in sensingpy/plot.py
plot_band¶
plot_band
¶
Plot a single band of an Image object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
Image object containing bands data and coordinate reference system |
required |
band
|
str
|
Band name to be plotted |
required |
ax
|
Axes
|
Matplotlib axes on which to plot the data |
required |
cmap
|
str
|
Colormap to use for visualization, by default 'viridis' |
'viridis'
|
**kwargs
|
Additional keyword arguments passed to ax.pcolormesh() |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[Axes, Any]
|
Axes with the plotted data and the mappable object for creating a colorbar |
Examples:
>>> fig, ax = get_geofigure(image.crs, 1, 1)
>>> ax, mappable = plot_band(image, 'nir', ax, cmap='inferno')
>>> plt.colorbar(mappable, ax=ax, label='NIR Reflectance')
Source code in sensingpy/plot.py
plot_rgb¶
plot_rgb
¶
plot_rgb(image: Image, red: str, green: str, blue: str, ax: Axes, brightness: float = 1, **kwargs) -> Axes
Create an RGB visualization from three bands of an Image object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
Image object containing bands data and coordinate reference system |
required |
red
|
str
|
Band name to use for the red channel |
required |
green
|
str
|
Band name to use for the green channel |
required |
blue
|
str
|
Band name to use for the blue channel |
required |
ax
|
Axes
|
Matplotlib axes on which to plot the RGB image |
required |
brightness
|
float
|
Value to multiply the RGB values to adjust brightness, by default 1 |
1
|
**kwargs
|
Additional keyword arguments passed to ax.pcolormesh() |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axes with the RGB image plotted |
Notes
This function handles both float (0-1) and uint8 (0-255) data types. Values are clipped to valid range after brightness adjustment.
Examples:
>>> fig, ax = get_geofigure(image.crs, 1, 1)
>>> ax = plot_rgb(image, 'red', 'green', 'blue', ax, brightness=1.5)
>>> plt.title('True Color Composite')
Source code in sensingpy/plot.py
add_gridlines¶
add_gridlines
¶
Add geographic gridlines to a cartopy axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Cartopy axes to which gridlines will be added |
required |
**kwargs
|
Additional keyword arguments passed to ax.gridlines() |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[Axes, Any]
|
Axes with added gridlines and the gridlines object for further customization |
Notes
Labels on top and right edges are disabled by default. The returned gridlines object can be used for additional customization.
Examples:
>>> fig, ax = get_geofigure(image.crs, 1, 1)
>>> ax, gl = add_gridlines(ax, linestyle='--')
>>> # Customize gridlines further if needed
>>> gl.xlabel_style = {'size': 15}
>>> gl.ylabel_style = {'color': 'gray'}