pyxplor.plot_binary

Module Contents

Functions

plot_binary(, output, super_title, super_title_font)

Plot the distribution of binary variables in a DataFrame, save the plot, and display it.

pyxplor.plot_binary.plot_binary(input_df: pandas.DataFrame, list_of_variables: list, plot_kind: str, label_offset: int = 10, label_fontsize: int = 10, plot_orientation: str = 'h', figsize: tuple = (10, 6), output: bool = False, super_title: str = 'Distribution of Binary Variables', super_title_font: int = 14) None[source]

Plot the distribution of binary variables in a DataFrame, save the plot, and display it.

This function will construct a set of subplots (either a bar plot or a pie chart) for each of the binary variables specified in list_of_variables. The function will save as well as display the entire figure.

Parameters:
  • input_df (pd.DataFrame) – The DataFrame that contains the binary variables.

  • list_of_variables (list) – List of binary variables (column names) to be plotted.

  • plot_kind ({'count', 'pie'}) – Type of plot to be generated, a count plot or a pie chart.

  • label_offset (int, optional) – Offset for label positioning. Default is 10. X-axis offset if orientation is horizontal. Y-axis offset if orientation is vertical.

  • label_fontsize (int, optional) – Font size for axis labels. Default is 10.

  • plot_orientation ({'h', 'v'}, optional) – The orientation of countplot, which can be either horizontal or vertical. Default is ‘h’.

  • figsize (tuple[int, 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 Binary Variables”.

  • super_title_font (int, optional) – Font size for the super title. Default is 14.

Returns:

  • fig (matplotlib.figure.Figure) – The matplotlib Figure object.

  • ax (matplotlib.axes._subplots.AxesSubplot) – The matplotlib Axes object.

Examples

binary = [“binary_var1”, “binary_var2”] fig, ax = plot_binary(df, binary, “count”)