inequality.pen.pen#

inequality.pen.pen(df, col, x, weight=None, ascending=True, xticks=True, total_bars=100, figsize=(8, 6), ax=None)[source]#

Creates the Pen’s Parade visualization.

This function generates a bar plot sorted by a specified column, with options to customize the x-axis ticks and figure size. The Pen’s Parade is a visual representation of income distribution (or similar data), typically used to show inequality.

Parameters:
dfpd.DataFrame

DataFrame containing the data to plot.

colstr

The column to plot on the y-axis.

xstr

The column to plot on the x-axis.

weightstr, optional

A column used to weight the bars in the Pen’s Parade. Default is None.

ascendingbool, optional

Whether to sort the DataFrame in ascending order by the col. Default is True.

xticksbool, optional

Whether to show x-axis ticks. Default is True.

total_barsint, optional

Total number of bars to create for the weighted Pen’s Parade. Default is 100.

figsizelist, optional

The size of the figure as a list [width, height]. Default is [8, 6].

axmatplotlib.axes.Axes, optional

Matplotlib Axes instance to plot on. If None, a new figure and axes will be created. Default is None.

Returns:
matplotlib.axes.Axes

A Matplotlib Axes object with the Pen’s Parade plot.