import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def
df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ex.explore_scatter_plot(df, x="log_gdp_pc", y="gini_regional").figexplore_scatter_plot
explore_scatter_plot(
df,
x=None,
y=None,
*,
color=None,
size=None,
loess=0,
alpha=None,
entity=None,
time=None,
connect=False,
title=None,
subtitle=None,
)Scatter plot of y against x with optional aesthetics and a LOESS smoother.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| df | pd.DataFrame | Data frame containing the variables. | required |
| x | str | None | Column names for the axes (both must be numeric). When omitted, they default to the declared roles (:func:expdpy.set_roles): x to the first covariate and y to the main outcome. |
None |
| y | str | None | Column names for the axes (both must be numeric). When omitted, they default to the declared roles (:func:expdpy.set_roles): x to the first covariate and y to the main outcome. |
None |
| color | str | None | Optional column mapped to marker color (numeric -> colorbar, otherwise discrete). | None |
| size | str | None | Optional numeric column mapped to marker size. | None |
| loess | Literal[0, 1, 2] | 0 no smoother, 1 unweighted LOESS, 2 LOESS weighted by size. |
0 |
| alpha | float | None | Marker opacity. If None, a sample-size-based default is used. |
None |
| entity | str | None | Cross-sectional (unit) identifier. Defaults to the panel entity declared via :func:expdpy.set_panel. Only used when connect=True. |
None |
| time | str | None | Time identifier used to order each unit’s trajectory when connect=True. Defaults to the panel time. |
None |
| connect | bool | If True (and an entity is available), draw a faint line connecting each unit’s points in time order — turning the scatter into a panel trajectory plot. |
False |
Returns
| Name | Type | Description |
|---|---|---|
| ScatterPlotResult | df (the complete-case frame plotted) and fig (the Plotly scatter). |
Examples
Basic — a plain scatter of two variables:
Advanced — map color and marker size to other columns, add a size-weighted LOESS smoother (the N-shaped Kuznets curve) and tune opacity:
import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def
df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ex.explore_scatter_plot(
df, x="log_gdp_pc", y="gini_regional",
color="continent", size="population", loess=2, alpha=0.6,
).fig