|
20 | 20 | from geopandas import GeoDataFrame |
21 | 21 | from matplotlib.axes import Axes |
22 | 22 | from matplotlib.backend_bases import RendererBase |
23 | | -from matplotlib.colors import Colormap, Normalize |
| 23 | +from matplotlib.colors import Colormap, LogNorm, Normalize |
24 | 24 | from matplotlib.figure import Figure |
25 | 25 | from mpl_toolkits.axes_grid1.inset_locator import inset_axes |
26 | 26 | from spatialdata import get_extent |
@@ -1299,6 +1299,18 @@ def _draw_colorbar( |
1299 | 1299 | base_offsets_axes: dict[str, float], |
1300 | 1300 | trackers_axes: dict[str, float], |
1301 | 1301 | ) -> None: |
| 1302 | + norm = spec.mappable.norm |
| 1303 | + if isinstance(norm, LogNorm): |
| 1304 | + vmin, vmax = norm.vmin, norm.vmax |
| 1305 | + if vmin is None or vmax is None or vmin <= 0 or vmin >= vmax: |
| 1306 | + warnings.warn( |
| 1307 | + "Data contains zeros or non-positive values; colorbar suppressed for `LogNorm`. " |
| 1308 | + "Pass `colorbar=False` to silence this warning, or clip the data to positive values.", |
| 1309 | + UserWarning, |
| 1310 | + stacklevel=2, |
| 1311 | + ) |
| 1312 | + return |
| 1313 | + |
1302 | 1314 | base_layout = { |
1303 | 1315 | "location": CBAR_DEFAULT_LOCATION, |
1304 | 1316 | "fraction": CBAR_DEFAULT_FRACTION, |
|
0 commit comments