pyxplor.plot_categorical
Module Contents
Functions
|
Plot the distribution of the categorical variables in a DataFrame, save the plot, and display it. |
- pyxplor.plot_categorical.plot_categorical(input_df: pandas.DataFrame, list_of_variables: list, yaxis_label_fontsize: int = 10, figsize: tuple = (10, 6), output: bool = False, super_title: str = 'Distribution of Categorical Variables', super_title_fontsize: int = 14, padding: tuple = (0.5, 0.5)) None[source]
Plot the distribution of the categorical variables in a DataFrame, save the plot, and display it.
This function will construct a set of subplots (all horizontal bar plots) for each of the categorical variables specified in list_of_variables (with 20 or less unqiue values). The function will display the entire figure (with option to save figure).
- Parameters:
input_df (pd.DataFrame) – The DataFrame that contains the categorical variables.
list_of_variables (list) – List of categorical variables (column names) to be plotted
yaxis_label_fontsize (int, optional) – Font size for y-axis tick labels (i.e. categorical values). Default is 10.
figsize (tuple[width: int, height: int], optional) – The width and height of the figure size in a tuple. Default is (10, 6).
output (bool, optional) – Whether to output the figure to the current working directory. Default is False.
super_title (str, optional) – Super title for the entire plot. Default is “Distribution of Categorical Variables”.
super_title_fontsize (int, optional) – Font size for the super title. Default is 14.
padding (tuple[hspace: int, wspace: int], optional) – The height and width padding between subplots in a tuple, as a fraction of the average Axes height. Default is (0.5, 0.5).
- Returns:
fig (matplotlib.figure.Figure) – The matplotlib Figure object.
ax (matplotlib.axes._subplots.AxesSubplot) – The matplotlib Axes object.
Examples
categorical = [“cat_var1”, “cat_var2”, “cat_var3”] fig, ax = plot_categorical(df, categorical)