Loess line
daspi.plotlib.plotter.LoessLine(source, target, feature, target_on_y=True, color=None, marker=None, show_scatter=False, show_fit_ci=False, confidence_level=0.95, fraction=0.2, order=3, kernel='gaussian', n_points=DEFAULT.LOWESS_SEQUENCE_LEN, kind='LOESS', ax=None, visible_spines=None, hide_axis=None, **kwds)
¶
Bases: Plotter
A class for plotting a loess line.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Pandas long format DataFrame containing the data source for the plot.
TYPE:
|
target
|
Column name of the target variable for the plot.
TYPE:
|
feature
|
Column name of the feature variable for the plot, by default ''
TYPE:
|
target_on_y
|
Flag indicating whether the target variable is plotted on the y-axis, by default True
TYPE:
|
color
|
Color to be used to draw the artists. If None, the first color is taken from the color cycle, by default None.
TYPE:
|
marker
|
The marker style for the scatter plot. Available markers see: https://matplotlib.org/stable/api/markers_api.html, by default None
TYPE:
|
show_scatter
|
Flag indicating whether to show the individual points, by default False.
TYPE:
|
show_fit_ci
|
Flag indicating whether to show the confidence interval for the lowess line as filled area, by default False.
TYPE:
|
confidence_level
|
Calculate confidence bands for the lowess line at this level (0 to 1). Defaults to 0.95.
TYPE:
|
fraction
|
The fraction of the data used for each local regression. A good value to start with is 2/3 (default value of statsmodels). Reduce the value to avoid underfitting. A value below 0.2 usually leads to overfitting, except for gaussian weights. Defaults to 0.2 because of default gaussian kernel.
TYPE:
|
order
|
The order of the local regression to be fitted. This determines the degree of the polynomial used in the local regression: 0: No smoothing (interpolation) 1: Linear regression 2: Quadratic regression 3: Cubic regression Default is 3.
TYPE:
|
kernel
|
The kernel function used to calculate the weights. Available kernels are: 'tricube': Tricube kernel function 'gaussian': Gaussian kernel function 'epanechnikov': Epanechnikov kernel function. Default is 'gaussian', because it will not run in a Singular Matrix Error.
TYPE:
|
n_points
|
Number of points the smoothed line and its sequence should have, by default LOWESS_SEQUENCE_LEN (defined in constants.py).
TYPE:
|
kind
|
The type of lowess line to be plotted. Available options are: 'LOESS': Lowess line using the LOESS algorithm 'LOWESS': Lowess line using the LOWESS algorithm Default is 'LOESS' because it needs less computational power.
TYPE:
|
ax
|
The axes object for the plot. If None, the current axes is
fetched using
TYPE:
|
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:
|
hide_axis
|
Specifies which axes should be hidden. If None, both axes are displayed. Defaults to None.
TYPE:
|
**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 LoessLine
fig, ax = plt.subplots()
x = 5*np.random.random(100)
df = pd.DataFrame(dict(
x = x,
y = np.sin(x) * 3*np.exp(-x) + np.random.normal(0, 0.2, 100)))
loess_line = LoessLine(
source=df, target='y', feature='x',
show_scatter=True, show_fit_ci=True, ax=ax)
loess_line(
kw_scatter=dict(color='black', s=10, alpha=0.5),
kw_fit_ci=dict(color='skyblue'),
color='deepskyblue')
Apply using the plot method of a DaSPi Chart object:
import numpy as np
import daspi as dsp
import pandas as pd
x = 5*np.random.random(100)
df = pd.DataFrame(dict(
x = x,
y = np.sin(x) * 3*np.exp(-x) + np.random.normal(0, 0.2, 100)))
chart = dsp.SingleChart(
source=df,
target='y',
feature='x'
).plot(
dsp.LoessLine,
show_scatter=True,
show_fit_ci=True,
kw_call=dict(
kw_scatter=dict(color='black', s=10, alpha=0.5),
kw_fit_ci=dict(color='skyblue'),
color='deepskyblue'))
show_scatter = show_scatter
instance-attribute
¶
Whether to show the individual points in the plot.
show_fit_ci = show_fit_ci
instance-attribute
¶
Whether to show the confidence interval for the fitted lowess line.
model = Model_(source=source, target=target, feature=feature)
instance-attribute
¶
The fitted results of the linear regression model.
kw_default
property
¶
Default keyword arguments for plotting (read-only)