Skip to content

Scatter

daspi.plotlib.plotter.CategoricalObservation(source, target, feature='', show_line=True, show_scatter=True, width=CATEGORY.FEATURE_SPACE, skip_na=None, target_on_y=True, color=None, marker=None, ax=None, visible_spines=None, hide_axis=None, **kwds)

Bases: TransformPlotter

TransformPlotter for visualizing the observation order, but for categorical features.

This class is designed to create a scatter, line, or a combination of these for categorical features. However, the individual points are displayed for each feature category, ordered by observation order, within the available categorical range.

PARAMETER DESCRIPTION
source

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

TYPE: pandas DataFrame

target

Column name of the target variable for the plot.

TYPE: str

feature

Column name of the feature variable for the plot, by default ''

TYPE: str DEFAULT: ''

show_line

Flag indicating whether to draw a line between the individual points, by default True

TYPE: bool DEFAULT: True

show_scatter

Flag indicating whether to show the individual points, by default True.

TYPE: bool DEFAULT: True

width

The width of the scatter range, by default CATEGORY.FEATURE_SPACE.

TYPE: float DEFAULT: FEATURE_SPACE

skip_na

Flag indicating whether to skip missing values in the feature grouped data, by default None - None, no missing values are skipped - all', grouped data is skipped if all values are missing - any', grouped data is skipped if any value is missing

TYPE: Literal['none', 'all', 'any'] DEFAULT: None

target_on_y

Flag indicating whether the target variable is plotted on the y-axis, by default True

TYPE: bool DEFAULT: True

color

Color to be used to draw the artists. If None, the first color is taken from the color cycle, by default None.

TYPE: str | None DEFAULT: None

marker

The marker style for the scatter plot. Available markers see: https://matplotlib.org/stable/api/markers_api.html, by default None

TYPE: str | 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 drawn according to the stylesheet. Defaults to None.

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

hide_axis

Specifies which axes should be hidden. If None, both axes are displayed. Defaults to None.

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

**kwds

Those arguments have no effect. Only serves to catch further arguments that have no use here (occurs when this class is used within chart objects).

DEFAULT: {}

Examples:

Apply to an existing Axes object:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from daspi import CategoricalObservation

fig, ax = plt.subplots()
df = pd.DataFrame(dict(
    x = ['first'] * 50 + ['second'] * 50 + ['third'] * 50,
    y = (
        list(np.random.normal(loc=3, scale=1, size=50))
        + list(np.random.normal(loc=4, scale=1, size=50))
        + list(np.random.normal(loc=2, scale=1, size=50)))))
observation = CategoricalObservation(
    source=df, target='y', feature='x', ax=ax,
    show_line=True, show_scatter=True,)
observation()
observation.label_feature_ticks()

Apply using the plot method of a DaSPi Chart object:

import numpy as np
import daspi as dsp
import pandas as pd

df = pd.DataFrame(dict(
    x = ['first'] * 50 + ['second'] * 50 + ['third'] * 50,
    y = (
        list(np.random.normal(loc=3, scale=1, size=50))
        + list(np.random.normal(loc=4, scale=1, size=50))
        + list(np.random.normal(loc=2, scale=1, size=50)))))
chart = dsp.SingleChart(
        source=df,
        target='y',
        feature='x',
        categorical_feature=True # neded to label feature ticks
    ).plot(
        dsp.CategoricalObservation,
        show_line=True,
        show_scatter=True,
    ).label() # neded to label feature ticks

width = width instance-attribute

The width of the categorical range.

show_line = show_line instance-attribute

Whether to draw a line between the individual points.

show_scatter = show_scatter instance-attribute

Whetter to draw the scatter points.

kw_default property

Default keyword arguments for plotting (read-only)

observation(loc, size)

Creates a uniform sequence of numbers with the number size from loc minus half the width to loc plus half the width.

PARAMETER DESCRIPTION
loc

Center position (feature axis) of the scatter values.

TYPE: float

size

Amount of valaues to generate

TYPE: int

RETURNS DESCRIPTION
1D array

Evenly distributed values.

transform(feature_data, target_data)

Normally randomize the target data for each feature value in the feature axis direction.

PARAMETER DESCRIPTION
feature_data

Base location (offset) of feature axis coming from `feature_grouped' generator.

TYPE: int | float

target_data

feature grouped target data used for transformation, coming from `feature_grouped' generator.

TYPE: pandas Series

RETURNS DESCRIPTION
data

The transformed data source for the plot.

TYPE: pandas DataFrame