wradlib.util.aspect#
- wradlib.util.aspect(obj)[source]#
Compute an aspect ratio that equalizes physical axis lengths.
The returned value can be passed to plotting functions (e.g. xarray or matplotlib) to scale the x and y axes such that one unit in x has the same physical length as one unit in y, independent of the array shape or data resolution.
- Parameters:
obj (
xarray.DataArrayorxarray.Dataset) – Object withxandycoordinates defining the spatial extent.- Returns:
float– Aspect ratio defined as(x_max - x_min) / (y_max - y_min).
Notes
This function uses coordinate ranges rather than array dimensions. It is therefore suitable for plots where the axes should reflect physical distances (e.g., meters, degrees) rather than pixel counts.
Examples
>>> ax = plt.gca() >>> da.plot(ax=ax, aspect=aspect(da))