countplot

hhpy.plotting.countplot(x: Union[Sequence[T_co], str] = None, data: pandas.core.frame.DataFrame = None, hue: str = None, ax: matplotlib.axes._axes.Axes = None, order: Union[Sequence[T_co], str] = None, hue_order: Union[Sequence[T_co], str] = None, normalize_x: bool = False, normalize_hue: bool = False, palette: Union[Mapping[KT, VT_co], Sequence[T_co], str] = None, x_tick_rotation: int = None, count_twinx: bool = False, hide_legend: bool = False, annotate: bool = True, annotate_format: str = ',.0f', legend_loc: str = 'upper right', barplot_kws: Mapping[KT, VT_co] = None, count_twinx_kws: Mapping[KT, VT_co] = None, **kwargs)[source]

Based on seaborn barplot but with a few more options, uses df_count()

Parameters:
  • x – Name of the x variable in data or vector data
  • data – Pandas DataFrame containing named data, optional if vector data is used
  • hue – Further split the plot by the levels of this variable [optional]
  • ax – The matplotlib.pyplot.Axes object to plot on, defaults to current axis [optional]
  • 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 order
    • count: sorted by value counts
    • mean, mean_ascending, mean_descending: sorted by mean value, defaults to descending
    • median, mean_ascending, median_descending: sorted by median value, defaults to descending
  • hue_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 order
    • count: sorted by value counts
    • mean, mean_ascending, mean_descending: sorted by mean value, defaults to descending
    • median, mean_ascending, median_descending: sorted by median value, defaults to descending
  • normalize_x – Whether to normalize x, causes the sum of each x group to be 100 percent [optional]
  • normalize_hue – Whether to normalize hue, causes the sum of each hue group to be 100 percent [optional]
  • palette – Collection of colors to be used for plotting. Can be a dictionary for with names for each level or a list of colors or an individual color name. Must be valid colors known to pyplot [optional]
  • x_tick_rotation – Set x tick label rotation to this value [optional]
  • count_twinx – Whether to plot the count values on the second axis (if using normalize) [optional]
  • hide_legend – Whether to hide the legend [optional]
  • annotate – Whether to use annotate_barplot [optional]
  • annotate_format – The format string used for annotations [optional]
  • legend_loc – Location of the legend, one of [bottom, right] or accepted value of pyplot.legendIf in [bottom, right] legend_outside is used, else pyplot.legend [optional]
  • barplot_kws – Additional keyword arguments passed to seaborn.barplot [optional]
  • count_twinx_kws – Additional keyword arguments passed to pyplot.plot [optional]
  • kwargs – Additional keyword arguments passed to df_count() [optional]
Returns:

The matplotlib.pyplot.Axes object with the plot on it