plotify-charts 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plotify/__init__.py +116 -0
- plotify/_inference.py +144 -0
- plotify/auto.py +360 -0
- plotify/base.py +224 -0
- plotify/categorical/__init__.py +37 -0
- plotify/categorical/bar_plot.py +121 -0
- plotify/categorical/circular_packing.py +107 -0
- plotify/categorical/dendrogram.py +113 -0
- plotify/categorical/doughnut_chart.py +109 -0
- plotify/categorical/lollipop_chart.py +168 -0
- plotify/categorical/parallel_coordinates.py +94 -0
- plotify/categorical/pie_chart.py +101 -0
- plotify/categorical/radar_chart.py +116 -0
- plotify/categorical/sunburst_diagram.py +117 -0
- plotify/categorical/treemap.py +121 -0
- plotify/categorical/venn_diagram.py +92 -0
- plotify/categorical/word_cloud.py +104 -0
- plotify/maps/__init__.py +21 -0
- plotify/maps/bubble_map.py +114 -0
- plotify/maps/cartogram.py +126 -0
- plotify/maps/choropleth_map.py +108 -0
- plotify/maps/connection_map.py +117 -0
- plotify/maps/hexbin_map.py +96 -0
- plotify/network/__init__.py +21 -0
- plotify/network/arc_diagram.py +124 -0
- plotify/network/chord_diagram.py +119 -0
- plotify/network/hierarchical_edge_bundling.py +141 -0
- plotify/network/network_diagram.py +167 -0
- plotify/network/sankey_diagram.py +258 -0
- plotify/num_cat/__init__.py +19 -0
- plotify/num_cat/box_plot_by_group.py +110 -0
- plotify/num_cat/grouped_bar_plot.py +110 -0
- plotify/num_cat/grouped_scatter.py +105 -0
- plotify/num_cat/stacked_bar_plot.py +117 -0
- plotify/numerical/__init__.py +21 -0
- plotify/numerical/boxplot.py +157 -0
- plotify/numerical/connected_scatter_plot.py +120 -0
- plotify/numerical/density_plot.py +184 -0
- plotify/numerical/scatter_plot.py +140 -0
- plotify/numerical/violin_plot.py +141 -0
- plotify/theme.py +297 -0
- plotify/timeseries/__init__.py +13 -0
- plotify/timeseries/area_chart.py +89 -0
- plotify/timeseries/line_chart.py +110 -0
- plotify/timeseries/stacked_area_chart.py +133 -0
- plotify/timeseries/stream_graph.py +116 -0
- plotify_charts-0.1.0.dist-info/LICENSE +21 -0
- plotify_charts-0.1.0.dist-info/METADATA +226 -0
- plotify_charts-0.1.0.dist-info/RECORD +50 -0
- plotify_charts-0.1.0.dist-info/WHEEL +4 -0
plotify/__init__.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Plotify
|
|
3
|
+
=======
|
|
4
|
+
|
|
5
|
+
A dual-backend (Seaborn/Matplotlib + Plotly) plotting package.
|
|
6
|
+
|
|
7
|
+
Top-level convenience imports re-export the plot classes from each
|
|
8
|
+
subpackage. For larger applications, prefer importing from the relevant
|
|
9
|
+
subpackage directly (e.g. ``from plotify.network import SankeyDiagram``).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
__version__ = "0.1.0"
|
|
13
|
+
|
|
14
|
+
# Smart picker + theme layer — the headline features.
|
|
15
|
+
from plotify import theme
|
|
16
|
+
from plotify.auto import Suggestion, auto, suggest
|
|
17
|
+
|
|
18
|
+
from plotify.categorical import (
|
|
19
|
+
BarPlot,
|
|
20
|
+
CircularPacking,
|
|
21
|
+
Dendrogram,
|
|
22
|
+
DoughnutChart,
|
|
23
|
+
LollipopChart,
|
|
24
|
+
ParallelCoordinates,
|
|
25
|
+
PieChart,
|
|
26
|
+
RadarChart,
|
|
27
|
+
SpiderChart,
|
|
28
|
+
SunburstDiagram,
|
|
29
|
+
Treemap,
|
|
30
|
+
VennDiagram,
|
|
31
|
+
WordCloudPlot,
|
|
32
|
+
)
|
|
33
|
+
from plotify.maps import (
|
|
34
|
+
BubbleMap,
|
|
35
|
+
Cartogram,
|
|
36
|
+
ChoroplethMap,
|
|
37
|
+
ConnectionMap,
|
|
38
|
+
HexbinMap,
|
|
39
|
+
)
|
|
40
|
+
from plotify.network import (
|
|
41
|
+
ArcDiagram,
|
|
42
|
+
ChordDiagram,
|
|
43
|
+
HierarchicalEdgeBundling,
|
|
44
|
+
NetworkDiagram,
|
|
45
|
+
SankeyDiagram,
|
|
46
|
+
)
|
|
47
|
+
from plotify.num_cat import (
|
|
48
|
+
BoxPlotByGroup,
|
|
49
|
+
GroupedBarPlot,
|
|
50
|
+
GroupedScatter,
|
|
51
|
+
StackedBarPlot,
|
|
52
|
+
)
|
|
53
|
+
from plotify.numerical import (
|
|
54
|
+
Boxplot,
|
|
55
|
+
ConnectedScatterPlot,
|
|
56
|
+
DensityPlot,
|
|
57
|
+
ScatterPlot,
|
|
58
|
+
Violinplot,
|
|
59
|
+
)
|
|
60
|
+
from plotify.timeseries import (
|
|
61
|
+
AreaChart,
|
|
62
|
+
LineChart,
|
|
63
|
+
StackedAreaChart,
|
|
64
|
+
StreamGraph,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
__all__ = [
|
|
68
|
+
"__version__",
|
|
69
|
+
# smart picker + theme
|
|
70
|
+
"Suggestion",
|
|
71
|
+
"auto",
|
|
72
|
+
"suggest",
|
|
73
|
+
"theme",
|
|
74
|
+
# numerical
|
|
75
|
+
"Boxplot",
|
|
76
|
+
"ConnectedScatterPlot",
|
|
77
|
+
"DensityPlot",
|
|
78
|
+
"ScatterPlot",
|
|
79
|
+
"Violinplot",
|
|
80
|
+
# categorical
|
|
81
|
+
"BarPlot",
|
|
82
|
+
"CircularPacking",
|
|
83
|
+
"Dendrogram",
|
|
84
|
+
"DoughnutChart",
|
|
85
|
+
"LollipopChart",
|
|
86
|
+
"ParallelCoordinates",
|
|
87
|
+
"PieChart",
|
|
88
|
+
"RadarChart",
|
|
89
|
+
"SpiderChart",
|
|
90
|
+
"SunburstDiagram",
|
|
91
|
+
"Treemap",
|
|
92
|
+
"VennDiagram",
|
|
93
|
+
"WordCloudPlot",
|
|
94
|
+
# num_cat
|
|
95
|
+
"BoxPlotByGroup",
|
|
96
|
+
"GroupedBarPlot",
|
|
97
|
+
"GroupedScatter",
|
|
98
|
+
"StackedBarPlot",
|
|
99
|
+
# timeseries
|
|
100
|
+
"AreaChart",
|
|
101
|
+
"LineChart",
|
|
102
|
+
"StackedAreaChart",
|
|
103
|
+
"StreamGraph",
|
|
104
|
+
# network
|
|
105
|
+
"ArcDiagram",
|
|
106
|
+
"ChordDiagram",
|
|
107
|
+
"HierarchicalEdgeBundling",
|
|
108
|
+
"NetworkDiagram",
|
|
109
|
+
"SankeyDiagram",
|
|
110
|
+
# maps
|
|
111
|
+
"BubbleMap",
|
|
112
|
+
"Cartogram",
|
|
113
|
+
"ChoroplethMap",
|
|
114
|
+
"ConnectionMap",
|
|
115
|
+
"HexbinMap",
|
|
116
|
+
]
|
plotify/_inference.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""
|
|
2
|
+
plotify._inference
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
Column-kind inference used by :mod:`plotify.auto`. Given a pandas Series we
|
|
6
|
+
classify it into one of a small set of "kinds" (numeric, datetime, low- /
|
|
7
|
+
mid- / high-cardinality categorical, text, boolean) so the suggestion
|
|
8
|
+
engine can make decisions without hard-coding pandas dtype strings.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from enum import Enum
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
import pandas as pd
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ColKind(str, Enum):
|
|
19
|
+
"""Categorical bucket assigned to each column."""
|
|
20
|
+
|
|
21
|
+
NUMERIC = "numeric"
|
|
22
|
+
DATETIME = "datetime"
|
|
23
|
+
BOOLEAN = "boolean"
|
|
24
|
+
CATEGORICAL_LOW = "categorical_low" # <= LOW_THRESHOLD unique values
|
|
25
|
+
CATEGORICAL_MID = "categorical_mid" # LOW < n_unique <= MID
|
|
26
|
+
CATEGORICAL_HIGH = "categorical_high" # > MID unique values
|
|
27
|
+
TEXT = "text"
|
|
28
|
+
UNKNOWN = "unknown"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# Thresholds used to bucket categorical columns. Tuned for "looks readable
|
|
32
|
+
# on a chart" rather than statistical correctness:
|
|
33
|
+
# - <= 10 : fits in a legend / x-axis without truncation
|
|
34
|
+
# - <= 50 : usable but crowded; wide+long shapes start to matter
|
|
35
|
+
LOW_THRESHOLD = 10
|
|
36
|
+
MID_THRESHOLD = 50
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class ColumnSummary:
|
|
41
|
+
"""Compact description of a single column.
|
|
42
|
+
|
|
43
|
+
Used by the suggestion engine — fields cover what the rule set actually
|
|
44
|
+
consults, not full descriptive statistics.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
name: str
|
|
48
|
+
kind: ColKind
|
|
49
|
+
n_unique: int
|
|
50
|
+
n_total: int
|
|
51
|
+
n_missing: int
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def is_categorical(self) -> bool:
|
|
55
|
+
return self.kind in (
|
|
56
|
+
ColKind.CATEGORICAL_LOW,
|
|
57
|
+
ColKind.CATEGORICAL_MID,
|
|
58
|
+
ColKind.CATEGORICAL_HIGH,
|
|
59
|
+
ColKind.BOOLEAN,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def is_numeric_like(self) -> bool:
|
|
64
|
+
return self.kind == ColKind.NUMERIC
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def infer_kind(series: pd.Series) -> ColKind:
|
|
68
|
+
"""Classify a pandas Series into a :class:`ColKind`.
|
|
69
|
+
|
|
70
|
+
The order of checks matters: datetime must be tested before numeric
|
|
71
|
+
(pandas datetimes are technically int64 under the hood) and boolean
|
|
72
|
+
must be tested before numeric (booleans pass numeric checks).
|
|
73
|
+
"""
|
|
74
|
+
if pd.api.types.is_datetime64_any_dtype(series):
|
|
75
|
+
return ColKind.DATETIME
|
|
76
|
+
if pd.api.types.is_bool_dtype(series):
|
|
77
|
+
return ColKind.BOOLEAN
|
|
78
|
+
if pd.api.types.is_numeric_dtype(series):
|
|
79
|
+
return ColKind.NUMERIC
|
|
80
|
+
|
|
81
|
+
# Anything left is object / string / category dtype. Bucket by cardinality.
|
|
82
|
+
n_unique = int(series.nunique(dropna=True))
|
|
83
|
+
if n_unique <= LOW_THRESHOLD:
|
|
84
|
+
return ColKind.CATEGORICAL_LOW
|
|
85
|
+
if n_unique <= MID_THRESHOLD:
|
|
86
|
+
return ColKind.CATEGORICAL_MID
|
|
87
|
+
|
|
88
|
+
# Rough heuristic: if the average string length is high, treat as free
|
|
89
|
+
# text rather than a categorical. Used so e.g. tweet bodies don't get
|
|
90
|
+
# plotted as a 10k-bar chart.
|
|
91
|
+
#
|
|
92
|
+
# ``is_string_dtype`` (rather than ``series.dtype == object``) is needed
|
|
93
|
+
# because newer pandas versions store string-only columns under
|
|
94
|
+
# ``StringDtype`` instead of ``object`` by default — checking ``object``
|
|
95
|
+
# alone misses them.
|
|
96
|
+
if pd.api.types.is_string_dtype(series):
|
|
97
|
+
try:
|
|
98
|
+
avg_len = series.dropna().astype(str).str.len().mean()
|
|
99
|
+
if avg_len and avg_len > 30:
|
|
100
|
+
return ColKind.TEXT
|
|
101
|
+
except Exception:
|
|
102
|
+
pass
|
|
103
|
+
return ColKind.CATEGORICAL_HIGH
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def summarise(series: pd.Series, name: str | None = None) -> ColumnSummary:
|
|
107
|
+
"""Return a :class:`ColumnSummary` for ``series``."""
|
|
108
|
+
return ColumnSummary(
|
|
109
|
+
name=name or (series.name if series.name is not None else ""),
|
|
110
|
+
kind=infer_kind(series),
|
|
111
|
+
n_unique=int(series.nunique(dropna=True)),
|
|
112
|
+
n_total=int(len(series)),
|
|
113
|
+
n_missing=int(series.isna().sum()),
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def summarise_columns(
|
|
118
|
+
df: pd.DataFrame, columns: list[str | None]
|
|
119
|
+
) -> dict[str, ColumnSummary]:
|
|
120
|
+
"""Summarise the given columns (skipping any ``None`` entries)."""
|
|
121
|
+
out: dict[str, ColumnSummary] = {}
|
|
122
|
+
for col in columns:
|
|
123
|
+
if col is None:
|
|
124
|
+
continue
|
|
125
|
+
if col not in df.columns:
|
|
126
|
+
raise KeyError(f"Column {col!r} not found in dataframe.")
|
|
127
|
+
out[col] = summarise(df[col], name=col)
|
|
128
|
+
return out
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# Used by tests and downstream callers that want a stable list of kinds.
|
|
132
|
+
__all__ = [
|
|
133
|
+
"ColKind",
|
|
134
|
+
"ColumnSummary",
|
|
135
|
+
"LOW_THRESHOLD",
|
|
136
|
+
"MID_THRESHOLD",
|
|
137
|
+
"infer_kind",
|
|
138
|
+
"summarise",
|
|
139
|
+
"summarise_columns",
|
|
140
|
+
]
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# Reference numpy to avoid linter warnings — pandas uses it internally.
|
|
144
|
+
_ = np.asarray([])
|
plotify/auto.py
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"""
|
|
2
|
+
plotify.auto
|
|
3
|
+
============
|
|
4
|
+
|
|
5
|
+
Smart chart picker. Given a dataframe and an ``(x, y, color)`` triple the
|
|
6
|
+
:func:`suggest` function returns a ranked list of chart suggestions based
|
|
7
|
+
on the inferred kinds (numeric / datetime / categorical / boolean) of the
|
|
8
|
+
chosen columns. :func:`auto` is a convenience wrapper that picks the top
|
|
9
|
+
suggestion and instantiates it.
|
|
10
|
+
|
|
11
|
+
The output of :func:`suggest` is a list of :class:`Suggestion` objects;
|
|
12
|
+
each carries the chart class, the kwargs to construct it with, a score in
|
|
13
|
+
``[0, 1]``, and a one-line reason explaining the rule that fired.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
|
|
18
|
+
import pandas as pd
|
|
19
|
+
|
|
20
|
+
from plotify._inference import ColKind, summarise_columns
|
|
21
|
+
|
|
22
|
+
# We import every chart class lazily inside _build_candidates so that
|
|
23
|
+
# importing ``plotify.auto`` doesn't drag in every dependency in the
|
|
24
|
+
# package — useful for users who only want the inference utilities.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class Suggestion:
|
|
29
|
+
"""A single chart suggestion produced by :func:`suggest`.
|
|
30
|
+
|
|
31
|
+
Attributes
|
|
32
|
+
----------
|
|
33
|
+
chart_class : type
|
|
34
|
+
The Plotify chart class to instantiate.
|
|
35
|
+
kwargs : dict
|
|
36
|
+
Keyword arguments to pass to ``chart_class`` (besides ``df`` and
|
|
37
|
+
``backend``).
|
|
38
|
+
score : float
|
|
39
|
+
Confidence in this suggestion, ``0..1``. The decision rules assign
|
|
40
|
+
rough scores; ranking is the consumer-facing contract.
|
|
41
|
+
reason : str
|
|
42
|
+
Human-readable one-line explanation of why this chart was picked.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
chart_class: type
|
|
46
|
+
kwargs: dict
|
|
47
|
+
score: float
|
|
48
|
+
reason: str
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def suggest(
|
|
52
|
+
df: pd.DataFrame,
|
|
53
|
+
x: str | None = None,
|
|
54
|
+
y: str | None = None,
|
|
55
|
+
color: str | None = None,
|
|
56
|
+
intent: str | None = None,
|
|
57
|
+
top_k: int = 5,
|
|
58
|
+
) -> list[Suggestion]:
|
|
59
|
+
"""Return ranked chart suggestions for ``df`` and the chosen columns.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
df : pandas.DataFrame
|
|
64
|
+
Input data.
|
|
65
|
+
x, y, color : str, optional
|
|
66
|
+
Column names. ``y`` is the value axis; ``color`` is the grouping
|
|
67
|
+
column. Single-column inputs (just ``x``) are also handled.
|
|
68
|
+
intent : str, optional
|
|
69
|
+
High-level user intent — currently understood values are
|
|
70
|
+
``"distribution"`` (force violin/box family) and
|
|
71
|
+
``"comparison"`` (force bars).
|
|
72
|
+
top_k : int, default=5
|
|
73
|
+
Maximum number of suggestions to return.
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
-------
|
|
77
|
+
list[Suggestion]
|
|
78
|
+
Up to ``top_k`` suggestions, ordered by descending score. Empty
|
|
79
|
+
list if no rule matched.
|
|
80
|
+
"""
|
|
81
|
+
summaries = summarise_columns(df, [x, y, color])
|
|
82
|
+
|
|
83
|
+
candidates = _build_candidates(
|
|
84
|
+
x_summary=summaries.get(x) if x else None,
|
|
85
|
+
y_summary=summaries.get(y) if y else None,
|
|
86
|
+
color_summary=summaries.get(color) if color else None,
|
|
87
|
+
intent=intent,
|
|
88
|
+
x_name=x,
|
|
89
|
+
y_name=y,
|
|
90
|
+
color_name=color,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
candidates.sort(key=lambda s: s.score, reverse=True)
|
|
94
|
+
return candidates[:top_k]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def auto(
|
|
98
|
+
df: pd.DataFrame,
|
|
99
|
+
x: str | None = None,
|
|
100
|
+
y: str | None = None,
|
|
101
|
+
color: str | None = None,
|
|
102
|
+
intent: str | None = None,
|
|
103
|
+
backend: str = "seaborn",
|
|
104
|
+
**plot_kwargs,
|
|
105
|
+
):
|
|
106
|
+
"""Pick the top-scoring chart for ``df`` and instantiate it.
|
|
107
|
+
|
|
108
|
+
Equivalent to ``suggest(df, ...)[0].chart_class(df, **kwargs)`` with
|
|
109
|
+
the suggestion's ``kwargs`` merged with ``plot_kwargs`` (the latter
|
|
110
|
+
wins on conflict).
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
BasePlot
|
|
115
|
+
The instantiated plot.
|
|
116
|
+
|
|
117
|
+
Raises
|
|
118
|
+
------
|
|
119
|
+
ValueError
|
|
120
|
+
If no rule matched the supplied columns.
|
|
121
|
+
"""
|
|
122
|
+
suggestions = suggest(df, x=x, y=y, color=color, intent=intent, top_k=1)
|
|
123
|
+
if not suggestions:
|
|
124
|
+
raise ValueError(
|
|
125
|
+
"Could not infer an appropriate chart from the supplied columns."
|
|
126
|
+
)
|
|
127
|
+
top = suggestions[0]
|
|
128
|
+
merged = {**top.kwargs, **plot_kwargs}
|
|
129
|
+
return top.chart_class(df, backend=backend, **merged)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
# ------------------------------------------------------------------ #
|
|
133
|
+
# Decision rules
|
|
134
|
+
# ------------------------------------------------------------------ #
|
|
135
|
+
def _build_candidates(
|
|
136
|
+
x_summary,
|
|
137
|
+
y_summary,
|
|
138
|
+
color_summary,
|
|
139
|
+
intent,
|
|
140
|
+
x_name,
|
|
141
|
+
y_name,
|
|
142
|
+
color_name,
|
|
143
|
+
):
|
|
144
|
+
"""Apply the decision rules and return a list of :class:`Suggestion`.
|
|
145
|
+
|
|
146
|
+
The rules are intentionally readable, not algorithmic — adding a new
|
|
147
|
+
chart usually means adding a new ``if`` branch here.
|
|
148
|
+
"""
|
|
149
|
+
# Lazy imports — see module docstring for reasoning.
|
|
150
|
+
from plotify.categorical import BarPlot, LollipopChart, PieChart
|
|
151
|
+
from plotify.num_cat import (
|
|
152
|
+
BoxPlotByGroup,
|
|
153
|
+
GroupedBarPlot,
|
|
154
|
+
GroupedScatter,
|
|
155
|
+
StackedBarPlot,
|
|
156
|
+
)
|
|
157
|
+
from plotify.numerical import Boxplot, DensityPlot, ScatterPlot, Violinplot
|
|
158
|
+
from plotify.timeseries import AreaChart, LineChart, StackedAreaChart
|
|
159
|
+
|
|
160
|
+
out: list[Suggestion] = []
|
|
161
|
+
|
|
162
|
+
xk = x_summary.kind if x_summary else None
|
|
163
|
+
yk = y_summary.kind if y_summary else None
|
|
164
|
+
ck = color_summary.kind if color_summary else None
|
|
165
|
+
has_color = color_summary is not None
|
|
166
|
+
|
|
167
|
+
# Helpers for readability of the ladder below.
|
|
168
|
+
is_low_cat = (xk == ColKind.CATEGORICAL_LOW or xk == ColKind.BOOLEAN)
|
|
169
|
+
color_is_low_cat = ck in (ColKind.CATEGORICAL_LOW, ColKind.BOOLEAN)
|
|
170
|
+
|
|
171
|
+
# ------ Intent overrides — applied first so they always rank highest.
|
|
172
|
+
if intent == "distribution" and yk == ColKind.NUMERIC and is_low_cat:
|
|
173
|
+
out.append(
|
|
174
|
+
Suggestion(
|
|
175
|
+
Violinplot,
|
|
176
|
+
{"x": x_name, "y": y_name},
|
|
177
|
+
0.97,
|
|
178
|
+
"intent=distribution + categorical x + numeric y → violin plot",
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
out.append(
|
|
182
|
+
Suggestion(
|
|
183
|
+
Boxplot,
|
|
184
|
+
{"x": x_name, "y": y_name},
|
|
185
|
+
0.92,
|
|
186
|
+
"intent=distribution + categorical x + numeric y → box plot",
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
return out
|
|
190
|
+
|
|
191
|
+
if intent == "distribution" and xk == ColKind.NUMERIC and y_summary is None:
|
|
192
|
+
out.append(
|
|
193
|
+
Suggestion(
|
|
194
|
+
DensityPlot, {"x": x_name}, 0.95, "intent=distribution + numeric → KDE"
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
out.append(
|
|
198
|
+
Suggestion(
|
|
199
|
+
Violinplot, {"y": x_name}, 0.85, "intent=distribution + numeric → violin"
|
|
200
|
+
)
|
|
201
|
+
)
|
|
202
|
+
return out
|
|
203
|
+
|
|
204
|
+
# ------ Time-series patterns: datetime x + numeric y ---------------
|
|
205
|
+
if xk == ColKind.DATETIME and yk == ColKind.NUMERIC:
|
|
206
|
+
if has_color and color_is_low_cat:
|
|
207
|
+
out.append(
|
|
208
|
+
Suggestion(
|
|
209
|
+
LineChart,
|
|
210
|
+
{"x": x_name, "y": y_name, "hue": color_name},
|
|
211
|
+
0.96,
|
|
212
|
+
"datetime x + numeric y + low-cardinality group → multi-series line chart",
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
out.append(
|
|
216
|
+
Suggestion(
|
|
217
|
+
StackedAreaChart,
|
|
218
|
+
{"x": x_name, "y": y_name, "hue": color_name},
|
|
219
|
+
0.72,
|
|
220
|
+
"stacked area variant for compositional time series",
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
else:
|
|
224
|
+
out.append(
|
|
225
|
+
Suggestion(
|
|
226
|
+
LineChart,
|
|
227
|
+
{"x": x_name, "y": y_name},
|
|
228
|
+
0.95,
|
|
229
|
+
"datetime x + numeric y → line chart",
|
|
230
|
+
)
|
|
231
|
+
)
|
|
232
|
+
out.append(
|
|
233
|
+
Suggestion(
|
|
234
|
+
AreaChart,
|
|
235
|
+
{"x": x_name, "y": y_name},
|
|
236
|
+
0.65,
|
|
237
|
+
"filled area variant for the same series",
|
|
238
|
+
)
|
|
239
|
+
)
|
|
240
|
+
return out
|
|
241
|
+
|
|
242
|
+
# ------ Two numeric columns ----------------------------------------
|
|
243
|
+
if xk == ColKind.NUMERIC and yk == ColKind.NUMERIC:
|
|
244
|
+
if has_color and color_is_low_cat:
|
|
245
|
+
out.append(
|
|
246
|
+
Suggestion(
|
|
247
|
+
GroupedScatter,
|
|
248
|
+
{"x": x_name, "y": y_name, "hue": color_name},
|
|
249
|
+
0.95,
|
|
250
|
+
"two numeric + low-cardinality group → grouped scatter",
|
|
251
|
+
)
|
|
252
|
+
)
|
|
253
|
+
else:
|
|
254
|
+
out.append(
|
|
255
|
+
Suggestion(
|
|
256
|
+
ScatterPlot,
|
|
257
|
+
{"x": x_name, "y": y_name},
|
|
258
|
+
0.95,
|
|
259
|
+
"two numeric → scatter plot",
|
|
260
|
+
)
|
|
261
|
+
)
|
|
262
|
+
return out
|
|
263
|
+
|
|
264
|
+
# ------ Categorical x + numeric y ----------------------------------
|
|
265
|
+
if is_low_cat and yk == ColKind.NUMERIC:
|
|
266
|
+
if has_color and color_is_low_cat:
|
|
267
|
+
out.append(
|
|
268
|
+
Suggestion(
|
|
269
|
+
GroupedBarPlot,
|
|
270
|
+
{"x": x_name, "y": y_name, "hue": color_name},
|
|
271
|
+
0.92,
|
|
272
|
+
"two categoricals + numeric → grouped bar",
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
out.append(
|
|
276
|
+
Suggestion(
|
|
277
|
+
BoxPlotByGroup,
|
|
278
|
+
{"x": x_name, "y": y_name, "hue": color_name},
|
|
279
|
+
0.85,
|
|
280
|
+
"use box plots if individual observations carry meaning",
|
|
281
|
+
)
|
|
282
|
+
)
|
|
283
|
+
out.append(
|
|
284
|
+
Suggestion(
|
|
285
|
+
StackedBarPlot,
|
|
286
|
+
{"x": x_name, "y": y_name, "hue": color_name},
|
|
287
|
+
0.7,
|
|
288
|
+
"stacked alternative if values compose a whole",
|
|
289
|
+
)
|
|
290
|
+
)
|
|
291
|
+
else:
|
|
292
|
+
out.append(
|
|
293
|
+
Suggestion(
|
|
294
|
+
BarPlot,
|
|
295
|
+
{"x": x_name, "y": y_name},
|
|
296
|
+
0.9,
|
|
297
|
+
"low-cardinality x + numeric y → bar plot",
|
|
298
|
+
)
|
|
299
|
+
)
|
|
300
|
+
out.append(
|
|
301
|
+
Suggestion(
|
|
302
|
+
LollipopChart,
|
|
303
|
+
{"x": x_name, "y": y_name},
|
|
304
|
+
0.7,
|
|
305
|
+
"lollipop alternative when bars feel heavy",
|
|
306
|
+
)
|
|
307
|
+
)
|
|
308
|
+
out.append(
|
|
309
|
+
Suggestion(
|
|
310
|
+
Boxplot,
|
|
311
|
+
{"x": x_name, "y": y_name},
|
|
312
|
+
0.72,
|
|
313
|
+
"box plot if there are multiple observations per category",
|
|
314
|
+
)
|
|
315
|
+
)
|
|
316
|
+
return out
|
|
317
|
+
|
|
318
|
+
# ------ Single numeric column → distribution -----------------------
|
|
319
|
+
if xk == ColKind.NUMERIC and y_summary is None:
|
|
320
|
+
out.append(
|
|
321
|
+
Suggestion(
|
|
322
|
+
DensityPlot,
|
|
323
|
+
{"x": x_name},
|
|
324
|
+
0.9,
|
|
325
|
+
"single numeric column → KDE density plot",
|
|
326
|
+
)
|
|
327
|
+
)
|
|
328
|
+
out.append(
|
|
329
|
+
Suggestion(
|
|
330
|
+
Boxplot,
|
|
331
|
+
{"y": x_name},
|
|
332
|
+
0.7,
|
|
333
|
+
"box plot summary alternative",
|
|
334
|
+
)
|
|
335
|
+
)
|
|
336
|
+
out.append(
|
|
337
|
+
Suggestion(
|
|
338
|
+
Violinplot,
|
|
339
|
+
{"y": x_name},
|
|
340
|
+
0.7,
|
|
341
|
+
"violin plot alternative",
|
|
342
|
+
)
|
|
343
|
+
)
|
|
344
|
+
return out
|
|
345
|
+
|
|
346
|
+
# ------ Single low-cardinality categorical → counts ----------------
|
|
347
|
+
if is_low_cat and y_summary is None:
|
|
348
|
+
out.append(
|
|
349
|
+
Suggestion(
|
|
350
|
+
PieChart,
|
|
351
|
+
{"names": x_name, "values": x_name},
|
|
352
|
+
0.4,
|
|
353
|
+
"single categorical → pie chart of counts (consider df.value_counts())",
|
|
354
|
+
)
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
return out
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
__all__ = ["Suggestion", "auto", "suggest"]
|