MCPcopy
hub / github.com/pydata/xarray / map_dataset

Method map_dataset

xarray/plot/facetgrid.py:656–718  ·  view source on GitHub ↗
(
        self: T_FacetGrid,
        func: Callable,
        x: Hashable | None = None,
        y: Hashable | None = None,
        hue: Hashable | None = None,
        hue_style: HueStyleOptions = None,
        add_guide: bool | None = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

654 return self
655
656 def map_dataset(
657 self: T_FacetGrid,
658 func: Callable,
659 x: Hashable | None = None,
660 y: Hashable | None = None,
661 hue: Hashable | None = None,
662 hue_style: HueStyleOptions = None,
663 add_guide: bool | None = None,
664 **kwargs: Any,
665 ) -> T_FacetGrid:
666 from xarray.plot.dataset_plot import _infer_meta_data
667
668 kwargs["add_guide"] = False
669
670 if kwargs.get("markersize"):
671 kwargs["size_mapping"] = _parse_size(
672 self.data[kwargs["markersize"]], kwargs.pop("size_norm", None)
673 )
674
675 meta_data = _infer_meta_data(
676 self.data, x, y, hue, hue_style, add_guide, funcname=func.__name__
677 )
678 kwargs["meta_data"] = meta_data
679
680 if hue and meta_data["hue_style"] == "continuous":
681 cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs(
682 func, self.data[hue].to_numpy(), **kwargs
683 )
684 kwargs["meta_data"]["cmap_params"] = cmap_params
685 kwargs["meta_data"]["cbar_kwargs"] = cbar_kwargs
686
687 kwargs["_is_facetgrid"] = True
688
689 if func.__name__ == "quiver" and "scale" not in kwargs:
690 raise ValueError("Please provide scale.")
691 # TODO: come up with an algorithm for reasonable scale choice
692
693 for d, ax in zip(self.name_dicts.flat, self.axs.flat, strict=True):
694 # None is the sentinel value
695 if d is not None:
696 subset = self.data.loc[d]
697 maybe_mappable = func(
698 ds=subset, x=x, y=y, hue=hue, hue_style=hue_style, ax=ax, **kwargs
699 )
700 # TODO: this is needed to get legends to work.
701 # but maybe_mappable is a list in that case :/
702 self._mappables.append(maybe_mappable)
703
704 self._finalize_grid(meta_data["xlabel"], meta_data["ylabel"])
705
706 if hue:
707 hue_label = meta_data.pop("hue_label", None)
708 self._hue_label = hue_label
709 if meta_data["add_legend"]:
710 self._hue_var = meta_data["hue"]
711 self.add_legend(label=hue_label)
712 elif meta_data["add_colorbar"]:
713 self.add_colorbar(label=hue_label, **cbar_kwargs)

Callers 1

_easy_facetgridFunction · 0.95

Calls 10

_finalize_gridMethod · 0.95
add_legendMethod · 0.95
add_colorbarMethod · 0.95
add_quiverkeyMethod · 0.95
_parse_sizeFunction · 0.90
_infer_meta_dataFunction · 0.85
funcFunction · 0.50
getMethod · 0.45
to_numpyMethod · 0.45

Tested by

no test coverage detected