scatter
AeroViz.plot.scatter.scatter
scatter(df: DataFrame, x: str, y: str, c: str | None = None, color: str | None = '#7a97c9', s: str | None = None, cmap='jet', regression=False, regression_line_color: str | None = xkcd_rgb['denim blue'], diagonal=False, ax: Axes | None = None, **kwargs) -> tuple[Figure, Axes]
Creates a scatter plot with optional color and size encoding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The DataFrame containing the data to plot. |
required |
x
|
str
|
The column name for the x-axis values. |
required |
y
|
str
|
The column name for the y-axis values. |
required |
c
|
str
|
The column name for c encoding. Default is None. |
None
|
color
|
str
|
The column name for color encoding. Default is None. |
'#7a97c9'
|
s
|
str
|
The column name for size encoding. Default is None. |
None
|
cmap
|
str
|
The colormap to use for the color encoding. Default is 'jet'. |
'jet'
|
regression
|
bool
|
If True, fits and plots a linear regression line. Default is False. |
False
|
regression_line_color
|
str
|
The color of the regression line. Default is 'sns.xkcd_rgb["denim blue"]'. |
xkcd_rgb['denim blue']
|
diagonal
|
bool
|
If True, plots a 1:1 diagonal line. Default is False. |
False
|
ax
|
Axes
|
The matplotlib Axes to plot on. If not provided, a new figure and axes are created. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to customize the plot, such as |
{}
|
Returns:
Name | Type | Description |
---|---|---|
fig |
Figure
|
The matplotlib Figure object. |
ax |
Axes
|
The matplotlib Axes object with the scatter plot. |
Notes
- If both
c
ands
are provided, the scatter plot will encode data points using both color and size. - If only
c
is provided, data points will be color-coded according to the values in thec
column. - If only
s
is provided, data points will be sized according to the values in thes
column. - If neither
c
nors
is provided, a basic scatter plot is created. - The
regression
option will add a linear regression line and display the equation on the plot. - The
diagonal
option will add a 1:1 reference line to the plot.
Examples:
>>> import pandas as pd
>>> from AeroViz.plot import scatter
>>> df = pd.DataFrame({
>>> 'x': [1, 2, 3, 4],
>>> 'y': [1.1, 2.0, 2.9, 4.1],
>>> 'color': [10, 20, 30, 40],
>>> 'size': [100, 200, 300, 400]
>>> })
>>> fig, ax = scatter(df, x='x', y='y', c='color', s='size', regression=True, diagonal=True)