Visualisation#
Standard plotting and mapping procedures.
Plot Plan Position Indicator (PPI) or Range Height Indicator (RHI). |
|
Plots a Crosshair for a Plan Position Indicator (PPI). |
|
Helper function to create curvelinear grid |
|
Plot the vertical scanning strategy. |
|
Plot 2-D plan view of |
|
Plot according to <plot_plan_and_vert> with the maximum values along the three axes of |
|
Add lines (points in the form Nx2) to axes |
|
Add patches (points in the form Nx2) to axes |
|
wradlib xarray SubAccessor methods for visualization. |
- wradlib.vis.plot(da, *, ax=111, fig=None, crs=None, func='pcolormesh', **kwargs)[source]#
Plot Plan Position Indicator (PPI) or Range Height Indicator (RHI).
The implementation of this plot routine is in cartesian axes and does all coordinate transforms using xarray machinery. This allows zooming into the data as well as making it easier to plot additional data (like gauge locations) without having to convert them to the radar’s polar coordinate system.
Using
crs='cg'
the plotting is done in a curvelinear grid axes.Additional data can be plotted in polar coordinates or cartesian coordinates depending on which axes object is used.
**kwargs
may be used to try to influence thematplotlib.pyplot.pcolormesh
,matplotlib.pyplot.contour
,matplotlib.pyplot.contourf
andwradlib.georef.polar.spherical_to_proj
routines under the hood.- Parameters
da (
xarray.DataArray
) – DataArray to plotcrs (
cartopy.crs.CRS
,dict
orNone
) – cartopy CRS Coordinate Reference System describing projection If this parameter is not None,site
must be set properly. Then the function will attempt to georeference the radar bins and display the PPI in the coordinate system defined by the projection string.fig (
matplotlib.figure.Figure
) – If given, the PPI/RHI will be plotted into this figure object. Axes are created as needed. If None, a new figure object will be created or current figure will be used, depending onax
.ax (
matplotlib.axes.Axes
ormatplotlib.gridspec.SubplotSpec
) – If matplotlib Axes object is given, the PPI will be plotted into this axes object. If matplotlib grid definition is given (nrows/ncols/plotnumber), axis are created in the specified place. Defaults to ‘111’, only one subplot/axis.func (
str
) – Name of plotting function to be used under the hood. Defaults to ‘pcolormesh’. ‘contour’ and ‘contourf’ can be selected too.
- Keyword Arguments
cmap (
str
, optional) – matplotlib colormap string. Defaults to wradlib default colormap, which is either Homeyer_Rainbow if cmweather is installed or turbo.zorder (
int
, optional) – Lower zorder values are drawn first. Defaults to 0.kwargs (
dict
, optional) – Further kwargs, which are propagated to xarray plotting functions.
- Returns
pm (
matplotlib.collections.QuadMesh
ormatplotlib.contour.QuadContourSet
) – The result of the plotting function. Necessary, if you want to add a colorbar to the plot.
Note
If
crs
contains a curvelinear grid dict, thecgax
- curvelinear Axes (r-theta-grid) is returned.caax
- Cartesian Axes (x-y-grid) andpaax
- parasite axes object for plotting polar data can be derived like this:caax = cgax.parasites[0] paax = cgax.parasites[1]
The function
create_cg
uses the Matplotlib AXISARTIST namespace.Here are some limitations to normal Matplotlib Axes (see AXES_GRID1).
Examples
See Quick-view a sweep in polar or cartesian reference systems, and Plot on curvelinear grid.
- wradlib.vis.plot_ppi_crosshair(site, ranges, angles=None, crs=None, elev=0.0, ax=None, **kwargs)[source]#
Plots a Crosshair for a Plan Position Indicator (PPI).
- Parameters
site (
tuple
) – Tuple of coordinates of the radar site. If crs is not used, this simply becomes the offset for the origin of the coordinate system. If crs is used, values must be given as (longitude, latitude, altitude) tuple of geographical coordinates.ranges (
list
) – List of ranges, for which range circles should be drawn. Ifcrs
is None arbitrary units may be used (such that they fit with the underlying PPI plot). Otherwise the ranges must be given in meters.angles (
list
, optional) – List of angles (in degrees) for which straight lines should be drawn. These lines will be drawn starting from the center and until the largest range. Defaults to [0, 90, 180, 270].crs (
osgeo.osr.SpatialReference
) – GDAL OSR Spatial Reference Object describing projection The function will calculate lines and circles according to georeferenced coordinates taking beam propagation, earth’s curvature and scale effects due to projection into account. Depending on the projection, crosshair lines might not be straight and range circles might appear elliptical (also check if the aspect of the axes might not also be responsible for this).elev (
float
ornumpy.ndarray
) – float or array of same shape as az Elevation angle of the scan or individual azimuths. May improve georeferencing coordinates for larger elevation angles. Defaults to 0.ax (
matplotlib.axes.Axes
) – If given, the crosshair will be plotted into this axes object. If None matplotlib’s current axes (function gca()) concept will be used to determine the axes.
- Keyword Arguments
line (
dict
) – dictionary, which will be passed to the crosshair line objects using the standard keyword inheritance mechanism. If not given defaults will be used.circle (
dict
) – dictionary, which will be passed to the range circle line objects using the standard keyword inheritance mechanism. If not given defaults will be used.
See also
plot_ppi
- Returns
ax (
matplotlib.axes.Axes
) – The axes object into which the PPI was plotted
Examples
See Quick-view a sweep in polar or cartesian reference systems.
- wradlib.vis.create_cg(*, fig=None, subplot=111, rot=-450, scale=-1, angular_spacing=10, radial_spacing=10, latmin=0, lon_cycle=360)[source]#
Helper function to create curvelinear grid
The function makes use of the Matplotlib AXISARTIST toolkit.
Here are some limitations to normal Matplotlib Axes. While using the Matplotlib AxesGrid1 Toolkit most of the limitations can be overcome. See Overview of axes_grid1 toolkit.
- Parameters
fig (
matplotlib.figure.Figure
) – If given, the PPI/RHI will be plotted into this figure object. Axes are created as needed. If None a new figure object will be created or current figure will be used, depending on “subplot”.subplot (
matplotlib.gridspec.SubplotSpec
) – nrows/ncols/plotnumber, see examples section defaults to ‘111’, only one subplotrot (
float
) – Rotation of the source data in degrees, defaults to -450 for PPI, use 0 for RHIscale (
float
) – Scale of source data, defaults to -1. for PPI, use 1 for RHIangular_spacing (
float
) – Spacing of the angular grid, defaults to 10.radial_spacing (
float
) – Spacing of the radial grid, defaults to 10.latmin (
float
) – Startvalue for radial grid, defaults to 0.lon_cycle (
float
) – Angular cycle, defaults to 360.
- Returns
cgax (
mpl_toolkits.axisartist.axis_artist.AxisArtist
) – curvelinear Axes (r-theta-grid)caax (
matplotlib.axes.Axes
) – matplotlib Axes object (twin to cgax) Cartesian Axes (x-y-grid) for plotting cartesian datapaax (
matplotlib.axes.Axes
) – matplotlib Axes object (parasite to cgax) The parasite axes object for plotting polar data
- wradlib.vis.plot_scan_strategy(ranges, elevs, site, *, beamwidth=1.0, vert_res=500.0, maxalt=10000.0, range_res=None, maxrange=None, units='m', terrain=None, az=0.0, cg=False, ax=111, cmap='tab10')[source]#
Plot the vertical scanning strategy.
- Parameters
ranges (sequence of
float
ornumpy.ndarray
) – sequence or array of float rangeselevs (sequence of
float
ornumpy.ndarray
) – elevation anglessite (sequence of
tuple
ornumpy.ndarray
) – radar site coordinates (longitude, latitude, altitude)beamwidth (
float
) – 3dB width of the radar beam, defaults to 1.0 deg.vert_res (
float
) – Vertical resolution in [m].maxalt (
float
) – Maximum altitude in [m].range_res (
float
) – Horizontal resolution in [m].maxrange (
float
) – Maximum range in [m].units (
str
) – Units to plot in, can be ‘m’ or ‘km’. Defaults to ‘m’.terrain (
bool
ornumpy.ndarray
) – If True, downloads srtm data and add orography for given az.az (
float
) – Used to specify azimuth for terrain plots.cg (
bool
) – If True, plot in curvelinear grid, defaults to False (cartesian grid).ax (
matplotlib.axes.Axes
ormatplotlib.gridspec.SubplotSpec
) – If matplotlib Axes object is given, the scan strategy will be plotted into this axes object. If matplotlib grid definition is given (nrows/ncols/plotnumber), axis are created in the specified place. Defaults to ‘111’, only one subplot/axis.cmap (
str
) – matplotlib colormap string.
- Returns
ax (
matplotlib.axes.Axes
) – matplotlib Axes or curvelinear Axes (matplotlib toolkit axisartist Axes object, r-theta-grid) depending on keyword argument cg.
- wradlib.vis.plot_plan_and_vert(x, y, z, dataxy, datazx, datazy, *, unit='', title='', **kwargs)[source]#
Plot 2-D plan view of
dataxy
together with vertical sectionsdataxz
anddatazy
- Parameters
x (
numpy.ndarray
) – array of x-axis coordinatesy (
numpy.ndarray
) – array of y-axis coordinatesz (
numpy.ndarray
) – array of z-axis coordinatesdataxy (
numpy.ndarray
) – 2d array of shape (len(x), len(y))datazx (
numpy.ndarray
) – 2d array of shape (len(z), len(x))datazy (
numpy.ndarray
) – 2d array of shape (len(z), len(y))unit (
str
) – unit of data arraystitle (
str
) – figure title
- Keyword Arguments
**kwargs (
dict
) – other kwargs which can be passed tomatplotlib.pyplot.contourf
- wradlib.vis.plot_max_plan_and_vert(x, y, z, data, *, unit='', title='', **kwargs)[source]#
Plot according to <plot_plan_and_vert> with the maximum values along the three axes of
data
Examples
See Recipe #2: Reading and visualizing an ODIM_H5 polar volume.
- wradlib.vis.add_lines(ax, lines, **kwargs)[source]#
Add lines (points in the form Nx2) to axes
Add lines (points in the form Nx2) to existing axes ax using
matplotlib.collections.LineCollection
.- Parameters
ax (
matplotlib.axes.Axes
)lines (
numpy.ndarray
) – nested Nx2 array(s)
Examples
See Plot geodata.
- wradlib.vis.add_patches(ax, patch_array, **kwargs)[source]#
Add patches (points in the form Nx2) to axes
Add patches (points in the form Nx2) to existing axes ax using
matplotlib.collections.PolyCollection
.- Parameters
ax (
matplotlib.axes.Axes
) – the axes object to plot onpatch_array (
numpy.ndarray
) – nested Nx2 array(s)
Examples
See Plot geodata.
- class wradlib.vis.VisMethods(obj)[source]#
Bases:
XarrayMethods
wradlib xarray SubAccessor methods for visualization.
- plot(*, ax=111, fig=None, crs=None, func='pcolormesh', **kwargs)[source]#
Plot Plan Position Indicator (PPI) or Range Height Indicator (RHI).
The implementation of this plot routine is in cartesian axes and does all coordinate transforms using xarray machinery. This allows zooming into the data as well as making it easier to plot additional data (like gauge locations) without having to convert them to the radar’s polar coordinate system.
Using
crs='cg'
the plotting is done in a curvelinear grid axes.Additional data can be plotted in polar coordinates or cartesian coordinates depending on which axes object is used.
**kwargs
may be used to try to influence thematplotlib.pyplot.pcolormesh
,matplotlib.pyplot.contour
,matplotlib.pyplot.contourf
andwradlib.georef.polar.spherical_to_proj
routines under the hood.- Parameters
da (
xarray.DataArray
) – DataArray to plotcrs (
cartopy.crs.CRS
,dict
orNone
) – cartopy CRS Coordinate Reference System describing projection If this parameter is not None,site
must be set properly. Then the function will attempt to georeference the radar bins and display the PPI in the coordinate system defined by the projection string.fig (
matplotlib.figure.Figure
) – If given, the PPI/RHI will be plotted into this figure object. Axes are created as needed. If None, a new figure object will be created or current figure will be used, depending onax
.ax (
matplotlib.axes.Axes
ormatplotlib.gridspec.SubplotSpec
) – If matplotlib Axes object is given, the PPI will be plotted into this axes object. If matplotlib grid definition is given (nrows/ncols/plotnumber), axis are created in the specified place. Defaults to ‘111’, only one subplot/axis.func (
str
) – Name of plotting function to be used under the hood. Defaults to ‘pcolormesh’. ‘contour’ and ‘contourf’ can be selected too.
- Keyword Arguments
cmap (
str
, optional) – matplotlib colormap string. Defaults to wradlib default colormap, which is either Homeyer_Rainbow if cmweather is installed or turbo.zorder (
int
, optional) – Lower zorder values are drawn first. Defaults to 0.kwargs (
dict
, optional) – Further kwargs, which are propagated to xarray plotting functions.
- Returns
pm (
matplotlib.collections.QuadMesh
ormatplotlib.contour.QuadContourSet
) – The result of the plotting function. Necessary, if you want to add a colorbar to the plot.
Note
If
crs
contains a curvelinear grid dict, thecgax
- curvelinear Axes (r-theta-grid) is returned.caax
- Cartesian Axes (x-y-grid) andpaax
- parasite axes object for plotting polar data can be derived like this:caax = cgax.parasites[0] paax = cgax.parasites[1]
The function
create_cg
uses the Matplotlib AXISARTIST namespace.Here are some limitations to normal Matplotlib Axes (see AXES_GRID1).
Examples
See Quick-view a sweep in polar or cartesian reference systems, and Plot on curvelinear grid.
- pcolormesh(*, ax=111, fig=None, crs=None, func='pcolormesh', **kwargs)[source]#
Plot Plan Position Indicator (PPI) or Range Height Indicator (RHI).
The implementation of this plot routine is in cartesian axes and does all coordinate transforms using xarray machinery. This allows zooming into the data as well as making it easier to plot additional data (like gauge locations) without having to convert them to the radar’s polar coordinate system.
Using
crs='cg'
the plotting is done in a curvelinear grid axes.Additional data can be plotted in polar coordinates or cartesian coordinates depending on which axes object is used.
**kwargs
may be used to try to influence thematplotlib.pyplot.pcolormesh
,matplotlib.pyplot.contour
,matplotlib.pyplot.contourf
andwradlib.georef.polar.spherical_to_proj
routines under the hood.- Parameters
da (
xarray.DataArray
) – DataArray to plotcrs (
cartopy.crs.CRS
,dict
orNone
) – cartopy CRS Coordinate Reference System describing projection If this parameter is not None,site
must be set properly. Then the function will attempt to georeference the radar bins and display the PPI in the coordinate system defined by the projection string.fig (
matplotlib.figure.Figure
) – If given, the PPI/RHI will be plotted into this figure object. Axes are created as needed. If None, a new figure object will be created or current figure will be used, depending onax
.ax (
matplotlib.axes.Axes
ormatplotlib.gridspec.SubplotSpec
) – If matplotlib Axes object is given, the PPI will be plotted into this axes object. If matplotlib grid definition is given (nrows/ncols/plotnumber), axis are created in the specified place. Defaults to ‘111’, only one subplot/axis.func (
str
) – Name of plotting function to be used under the hood. Defaults to ‘pcolormesh’. ‘contour’ and ‘contourf’ can be selected too.
- Keyword Arguments
cmap (
str
, optional) – matplotlib colormap string. Defaults to wradlib default colormap, which is either Homeyer_Rainbow if cmweather is installed or turbo.zorder (
int
, optional) – Lower zorder values are drawn first. Defaults to 0.kwargs (
dict
, optional) – Further kwargs, which are propagated to xarray plotting functions.
- Returns
pm (
matplotlib.collections.QuadMesh
ormatplotlib.contour.QuadContourSet
) – The result of the plotting function. Necessary, if you want to add a colorbar to the plot.
Note
If
crs
contains a curvelinear grid dict, thecgax
- curvelinear Axes (r-theta-grid) is returned.caax
- Cartesian Axes (x-y-grid) andpaax
- parasite axes object for plotting polar data can be derived like this:caax = cgax.parasites[0] paax = cgax.parasites[1]
The function
create_cg
uses the Matplotlib AXISARTIST namespace.Here are some limitations to normal Matplotlib Axes (see AXES_GRID1).
Examples
See Quick-view a sweep in polar or cartesian reference systems, and Plot on curvelinear grid.
- contour(*, ax=111, fig=None, crs=None, func='pcolormesh', **kwargs)[source]#
Plot Plan Position Indicator (PPI) or Range Height Indicator (RHI).
The implementation of this plot routine is in cartesian axes and does all coordinate transforms using xarray machinery. This allows zooming into the data as well as making it easier to plot additional data (like gauge locations) without having to convert them to the radar’s polar coordinate system.
Using
crs='cg'
the plotting is done in a curvelinear grid axes.Additional data can be plotted in polar coordinates or cartesian coordinates depending on which axes object is used.
**kwargs
may be used to try to influence thematplotlib.pyplot.pcolormesh
,matplotlib.pyplot.contour
,matplotlib.pyplot.contourf
andwradlib.georef.polar.spherical_to_proj
routines under the hood.- Parameters
da (
xarray.DataArray
) – DataArray to plotcrs (
cartopy.crs.CRS
,dict
orNone
) – cartopy CRS Coordinate Reference System describing projection If this parameter is not None,site
must be set properly. Then the function will attempt to georeference the radar bins and display the PPI in the coordinate system defined by the projection string.fig (
matplotlib.figure.Figure
) – If given, the PPI/RHI will be plotted into this figure object. Axes are created as needed. If None, a new figure object will be created or current figure will be used, depending onax
.ax (
matplotlib.axes.Axes
ormatplotlib.gridspec.SubplotSpec
) – If matplotlib Axes object is given, the PPI will be plotted into this axes object. If matplotlib grid definition is given (nrows/ncols/plotnumber), axis are created in the specified place. Defaults to ‘111’, only one subplot/axis.func (
str
) – Name of plotting function to be used under the hood. Defaults to ‘pcolormesh’. ‘contour’ and ‘contourf’ can be selected too.
- Keyword Arguments
cmap (
str
, optional) – matplotlib colormap string. Defaults to wradlib default colormap, which is either Homeyer_Rainbow if cmweather is installed or turbo.zorder (
int
, optional) – Lower zorder values are drawn first. Defaults to 0.kwargs (
dict
, optional) – Further kwargs, which are propagated to xarray plotting functions.
- Returns
pm (
matplotlib.collections.QuadMesh
ormatplotlib.contour.QuadContourSet
) – The result of the plotting function. Necessary, if you want to add a colorbar to the plot.
Note
If
crs
contains a curvelinear grid dict, thecgax
- curvelinear Axes (r-theta-grid) is returned.caax
- Cartesian Axes (x-y-grid) andpaax
- parasite axes object for plotting polar data can be derived like this:caax = cgax.parasites[0] paax = cgax.parasites[1]
The function
create_cg
uses the Matplotlib AXISARTIST namespace.Here are some limitations to normal Matplotlib Axes (see AXES_GRID1).
Examples
See Quick-view a sweep in polar or cartesian reference systems, and Plot on curvelinear grid.
- contourf(*, ax=111, fig=None, crs=None, func='pcolormesh', **kwargs)[source]#
Plot Plan Position Indicator (PPI) or Range Height Indicator (RHI).
The implementation of this plot routine is in cartesian axes and does all coordinate transforms using xarray machinery. This allows zooming into the data as well as making it easier to plot additional data (like gauge locations) without having to convert them to the radar’s polar coordinate system.
Using
crs='cg'
the plotting is done in a curvelinear grid axes.Additional data can be plotted in polar coordinates or cartesian coordinates depending on which axes object is used.
**kwargs
may be used to try to influence thematplotlib.pyplot.pcolormesh
,matplotlib.pyplot.contour
,matplotlib.pyplot.contourf
andwradlib.georef.polar.spherical_to_proj
routines under the hood.- Parameters
da (
xarray.DataArray
) – DataArray to plotcrs (
cartopy.crs.CRS
,dict
orNone
) – cartopy CRS Coordinate Reference System describing projection If this parameter is not None,site
must be set properly. Then the function will attempt to georeference the radar bins and display the PPI in the coordinate system defined by the projection string.fig (
matplotlib.figure.Figure
) – If given, the PPI/RHI will be plotted into this figure object. Axes are created as needed. If None, a new figure object will be created or current figure will be used, depending onax
.ax (
matplotlib.axes.Axes
ormatplotlib.gridspec.SubplotSpec
) – If matplotlib Axes object is given, the PPI will be plotted into this axes object. If matplotlib grid definition is given (nrows/ncols/plotnumber), axis are created in the specified place. Defaults to ‘111’, only one subplot/axis.func (
str
) – Name of plotting function to be used under the hood. Defaults to ‘pcolormesh’. ‘contour’ and ‘contourf’ can be selected too.
- Keyword Arguments
cmap (
str
, optional) – matplotlib colormap string. Defaults to wradlib default colormap, which is either Homeyer_Rainbow if cmweather is installed or turbo.zorder (
int
, optional) – Lower zorder values are drawn first. Defaults to 0.kwargs (
dict
, optional) – Further kwargs, which are propagated to xarray plotting functions.
- Returns
pm (
matplotlib.collections.QuadMesh
ormatplotlib.contour.QuadContourSet
) – The result of the plotting function. Necessary, if you want to add a colorbar to the plot.
Note
If
crs
contains a curvelinear grid dict, thecgax
- curvelinear Axes (r-theta-grid) is returned.caax
- Cartesian Axes (x-y-grid) andpaax
- parasite axes object for plotting polar data can be derived like this:caax = cgax.parasites[0] paax = cgax.parasites[1]
The function
create_cg
uses the Matplotlib AXISARTIST namespace.Here are some limitations to normal Matplotlib Axes (see AXES_GRID1).
Examples
See Quick-view a sweep in polar or cartesian reference systems, and Plot on curvelinear grid.