facet_wrap¶
-
hhpy.plotting.
facet_wrap
(func: Callable, data: pandas.core.frame.DataFrame, facet: Union[list, str], *args, facet_type: str = None, col_wrap: int = 4, width: int = None, height: int = None, catch_error: bool = True, return_fig_ax: bool = None, sharex: bool = False, sharey: bool = False, show_xlabel: bool = True, x_tick_rotation: int = None, y_tick_rotation: int = None, ax_title: str = 'set', order: Union[list, str] = None, subplots_kws: Mapping[KT, VT_co] = None, **kwargs)[source]¶ modeled after r’s facet_wrap function. Wraps a number of subplots onto a 2d grid of subplots while creating a new line after col_wrap columns. Uses a given plot function and creates a new plot for each facet level.
Parameters: - func – Any plot function. Must support keyword arguments data and ax
- data – Pandas DataFrame containing named data, optional if vector data is used
- facet – The column / list of columns to facet over.
- args – passed to func
- facet_type – one of [‘group’, ‘cols’, None]. If group facet is treated as the column creating the facet levels and a subplot is created for each level. If cols each facet is in turn passed as the first positional argument to the plot function func. If None then the facet_type is inferred: a single facet value will be treated as group and multiple facet values will be treated as cols.
- col_wrap – After how many columns to create a new line of subplots [optional]
- width – Width of each individual subplot [optional]
- height – Height of each individual subplot [optional]
- catch_error – whether to keep going in case of an error being encountered in the plot function [optional]
- return_fig_ax – Whether to return the figure and axes objects as tuple to be captured as fig,ax = …, If False pyplot.show() is called and the plot returns None [optional]
- sharex – Whether to share the x axis [optional]
- sharey – Whether to share the y axis [optional]
- show_xlabel – whether to show the x label for each subplot
- x_tick_rotation – x tick rotation for each subplot
- y_tick_rotation – y tick rotation for each subplot
- ax_title – one of [‘set’,’hide’], if set sets axis title to facet name, if hide forcefully hids axis title
- order –
Either a string describing how the (hue) levels or to be ordered or an explicit list of levels to be used for plotting. Accepted strings are:
sorted
: following python standard sorting conventions (alphabetical for string, ascending for value)inv
: following python standard sorting conventions but in inverse ordercount
: sorted by value countsmean
,mean_ascending
,mean_descending
: sorted by mean value, defaults to descendingmedian
,mean_ascending
,median_descending
: sorted by median value, defaults to descending
- subplots_kws – other keyword arguments passed to pyplot.subplots
- kwargs – other keyword arguments passed to func
Returns: if return_fig_ax: figure and axes objects as tuple, else None
Examples
Check out the example notebook