Apply a plotting function to a 2d facet's subset of the data. This is more convenient and less general than ``FacetGrid.map`` Parameters ---------- func : callable A plotting function with the same signature as a 2d xarray plotting m
(
self: T_FacetGrid,
func: Callable,
x: Hashable | None,
y: Hashable | None,
**kwargs: Any,
)
| 350 | return self.axs[-1, :] |
| 351 | |
| 352 | def map_dataarray( |
| 353 | self: T_FacetGrid, |
| 354 | func: Callable, |
| 355 | x: Hashable | None, |
| 356 | y: Hashable | None, |
| 357 | **kwargs: Any, |
| 358 | ) -> T_FacetGrid: |
| 359 | """ |
| 360 | Apply a plotting function to a 2d facet's subset of the data. |
| 361 | |
| 362 | This is more convenient and less general than ``FacetGrid.map`` |
| 363 | |
| 364 | Parameters |
| 365 | ---------- |
| 366 | func : callable |
| 367 | A plotting function with the same signature as a 2d xarray |
| 368 | plotting method such as `xarray.plot.imshow` |
| 369 | x, y : string |
| 370 | Names of the coordinates to plot on x, y axes |
| 371 | **kwargs |
| 372 | additional keyword arguments to func |
| 373 | |
| 374 | Returns |
| 375 | ------- |
| 376 | self : FacetGrid object |
| 377 | |
| 378 | """ |
| 379 | |
| 380 | if kwargs.get("cbar_ax") is not None: |
| 381 | raise ValueError("cbar_ax not supported by FacetGrid.") |
| 382 | |
| 383 | cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs( |
| 384 | func, self.data.to_numpy(), **kwargs |
| 385 | ) |
| 386 | |
| 387 | self._cmap_extend = cmap_params.get("extend") |
| 388 | |
| 389 | # Order is important |
| 390 | func_kwargs = { |
| 391 | k: v |
| 392 | for k, v in kwargs.items() |
| 393 | if k not in {"cmap", "colors", "cbar_kwargs", "levels"} |
| 394 | } |
| 395 | func_kwargs.update(cmap_params) |
| 396 | # to avoid redundant calling, colorbar and labelling is instead handled |
| 397 | # by `_finalize_grid` at the end |
| 398 | func_kwargs["add_colorbar"] = False |
| 399 | if func.__name__ != "surface": |
| 400 | func_kwargs["add_labels"] = False |
| 401 | |
| 402 | # Get x, y labels for the first subplot |
| 403 | x, y = _infer_xy_labels( |
| 404 | darray=self.data.loc[self.name_dicts.flat[0]], |
| 405 | x=x, |
| 406 | y=y, |
| 407 | imshow=func.__name__ == "imshow", |
| 408 | rgb=kwargs.get("rgb"), |
| 409 | ) |