arviz_plots.PlotCollection.facet_map

arviz_plots.PlotCollection.facet_map#

PlotCollection.facet_map(func, func_label=None, *, var_names=None, filter_vars=None, coords=None, **kwargs)[source]#

Apply a visual function to plots filtered by variable names and coordinates.

This is a convenience wrapper around map that uses the same var_names and coords interface as plotting functions like plot_dist.

Parameters:
funcstr or callable

Visual function to apply. If a string, it’s looked up in the visuals module (e.g., “set_xlim” becomes arviz_plots.visuals.set_xlim).

func_labelstr, optional

Variable name with which to store the object returned by func. Defaults to fun.__name__.

var_namesstr or list of str, optional

Variables to apply the function to. If not provided, applies to all variables.

filter_vars{None, “like”, “regex”}, default None
coordsmapping, optional

Coordinates to filter which plots get updated. Only plots with matching coordinate values will be affected.

**kwargs

Passed to map.

Returns:
PlotCollection

Returns self to allow method chaining.

See also

arviz_plots.PlotCollection.map

apply a function as many times as needed given faceting and aesthetic mappings

Notes

When calling map it sets ignore_aes as “all” if not present, and if a “labeller” key is present in kwargs but has None as value, the value is updated to either BaseLabeller or NoVarLabeller (if the variable isn’t used for facetting)

Examples

Set x-axis limits on a specific variable:

import arviz_base as azb
import arviz_plots as azp
data = azb.load_arviz_data("centered_eight")
pc = azp.plot_dist(data)
pc.facet_map("set_xlim", limits=(-15, 15), var_names="mu")
../../_images/arviz_plots.PlotCollection.facet_map_0_0.png

Apply with coordinate filtering:

pc = azp.plot_dist(data, coords={"school": ["Choate", "Deerfield", "Hotchkiss"]})
pc.facet_map(
    "set_xlim",
    limits=(-5, 5),
    coords={"school": ["Choate", "Deerfield"]}
)
../../_images/arviz_plots.PlotCollection.facet_map_1_0.png

Note that the same way that plot_dist with no variable names specified plots all of them, applying the filtering only to the relevant ones, facet_map behaves the same when coords are given but no variable names.