Skip to content

Plotter

daspi.plotlib.plotter.Plotter(source, target, feature='', target_on_y=True, color=None, marker=None, ax=None, visible_spines=None, hide_axis=None, **kwds)

Bases: ABC

Abstract base class for creating plotters.

This class serves as a blueprint for plotter implementations, facilitating the visualization of data from a given source.

PARAMETER DESCRIPTION
source

A long format DataFrame containing the data source for the plot.

TYPE: DataFrame

target

The column name of the target variable to be plotted.

TYPE: str

feature

The column name of the feature variable to be plotted. Defaults to an empty string ('').

TYPE: str DEFAULT: ''

target_on_y

A flag indicating whether the target variable is plotted on the y-axis. Defaults to True.

TYPE: bool DEFAULT: True

color

The color used for drawing the plot elements. If None, the first color from the color cycle is used. Defaults to None.

TYPE: str or None DEFAULT: None

marker

The marker style for scatter plots. For available markers, see: https://matplotlib.org/stable/api/markers_api.html. Defaults to None.

TYPE: str or None DEFAULT: None

ax

The axes object for the plot. If None, the current axes is fetched using plt.gca(). If no axes are available, a new one is created. Defaults to None.

TYPE: Axes | None DEFAULT: None

visible_spines

Specifies which spines are visible, the others are hidden. If 'none', no spines are visible. If None, the spines are drawnaccording to the stylesheet. Defaults to None.

TYPE: Literal['target', 'feature', 'none'] | None DEFAULT: None

hide_axis

Specifies which axes should be hidden. If None, no changes are made, and the axes are displayed according to the stylesheet. Defaults to None.

TYPE: Literal['target', 'feature', 'both'] | None DEFAULT: None

**kwds

Additional keyword arguments that are ignored in this class but may be used for compatibility with chart objects.

DEFAULT: {}

Notes

This class is intended to be subclassed, and specific plotting functionality should be implemented in derived classes.

fig instance-attribute

The top level container for all the plot elements.

ax instance-attribute

The axes object for the plot.

target_on_y = target_on_y instance-attribute

Flag indicating whether the target variable is plotted on the y-axis.

source = source instance-attribute

The data source for the plot

feature = feature instance-attribute

The column name of the feature variable.

target = target instance-attribute

The column name of the target variable.

visible_spines property writable

Get which spines are visible if specified.

Set which spines should be visible, the others are hidden. If 'none', no spines are visible. If None, no changes are made and the spines are drawn according to the stylesheet.

kw_default abstractmethod property

Override this property to provide the default keyword arguments for plotting as read-only.

x_column property

Get column name used to access data for x-axis (read-only).

y_column property

Get column name used to access data for y-axis (read-only).

x property

Get values used for x-axis (read-only).

y property

Get values used for y-axis (read-only)

color property

Get color of drawn artist

marker property

Get marker of drawn artist

figure_axes(ax) staticmethod

Create a figure and axes object if not provided.

shared_axes(ax, which, exclude=True) staticmethod

Get all the axes from the figure of the given ax and compare whether the ax share the given axis. Get a map of boolean values as a list where all are True when the axis is shared.

PARAMETER DESCRIPTION
ax

Base axes object to add second axis

TYPE: Axes

which

From which axis a second one should be added

TYPE: (x, y) DEFAULT: 'x'

exclude

If True excludes the given ax in the returned map

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
List[bool]

Flat map for axes that shares same axis

label_feature_ticks()

Label the feature ticks with categorical feature names.

This method gets the original feature values from the source DataFrame and labels the feature ticks with the feature names. Call this method if feature values are categorical.

target_as_percentage(xmax=1.0, decimals=None, symbol='%')

Format the numbers on target axis to percentage.

PARAMETER DESCRIPTION
xmax

Determines how the number is converted into a percentage. xmax is the data value that corresponds to 100%. Percentages are computed as x / xmax * 100. So if the data is already scaled to be percentages, xmax will be 100. Another common situation is where xmax is 1.0.

TYPE: float DEFAULT: 1.0

decimals

The number of decimal places to place after the point. If None (the default), the number will be computed automatically.

TYPE: int | None DEFAULT: None

symbol

A string that will be appended to the label. It may be None or empty to indicate that no symbol should be used. LaTeX special characters are escaped in symbol whenever latex mode is enabled, unless is_latex is True.

TYPE: str | None DEFAULT: '%'