plotify-charts 0.1.0__tar.gz

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.
Files changed (50) hide show
  1. plotify_charts-0.1.0/LICENSE +21 -0
  2. plotify_charts-0.1.0/PKG-INFO +226 -0
  3. plotify_charts-0.1.0/README.md +185 -0
  4. plotify_charts-0.1.0/plotify/__init__.py +116 -0
  5. plotify_charts-0.1.0/plotify/_inference.py +144 -0
  6. plotify_charts-0.1.0/plotify/auto.py +360 -0
  7. plotify_charts-0.1.0/plotify/base.py +224 -0
  8. plotify_charts-0.1.0/plotify/categorical/__init__.py +37 -0
  9. plotify_charts-0.1.0/plotify/categorical/bar_plot.py +121 -0
  10. plotify_charts-0.1.0/plotify/categorical/circular_packing.py +107 -0
  11. plotify_charts-0.1.0/plotify/categorical/dendrogram.py +113 -0
  12. plotify_charts-0.1.0/plotify/categorical/doughnut_chart.py +109 -0
  13. plotify_charts-0.1.0/plotify/categorical/lollipop_chart.py +168 -0
  14. plotify_charts-0.1.0/plotify/categorical/parallel_coordinates.py +94 -0
  15. plotify_charts-0.1.0/plotify/categorical/pie_chart.py +101 -0
  16. plotify_charts-0.1.0/plotify/categorical/radar_chart.py +116 -0
  17. plotify_charts-0.1.0/plotify/categorical/sunburst_diagram.py +117 -0
  18. plotify_charts-0.1.0/plotify/categorical/treemap.py +121 -0
  19. plotify_charts-0.1.0/plotify/categorical/venn_diagram.py +92 -0
  20. plotify_charts-0.1.0/plotify/categorical/word_cloud.py +104 -0
  21. plotify_charts-0.1.0/plotify/maps/__init__.py +21 -0
  22. plotify_charts-0.1.0/plotify/maps/bubble_map.py +114 -0
  23. plotify_charts-0.1.0/plotify/maps/cartogram.py +126 -0
  24. plotify_charts-0.1.0/plotify/maps/choropleth_map.py +108 -0
  25. plotify_charts-0.1.0/plotify/maps/connection_map.py +117 -0
  26. plotify_charts-0.1.0/plotify/maps/hexbin_map.py +96 -0
  27. plotify_charts-0.1.0/plotify/network/__init__.py +21 -0
  28. plotify_charts-0.1.0/plotify/network/arc_diagram.py +124 -0
  29. plotify_charts-0.1.0/plotify/network/chord_diagram.py +119 -0
  30. plotify_charts-0.1.0/plotify/network/hierarchical_edge_bundling.py +141 -0
  31. plotify_charts-0.1.0/plotify/network/network_diagram.py +167 -0
  32. plotify_charts-0.1.0/plotify/network/sankey_diagram.py +258 -0
  33. plotify_charts-0.1.0/plotify/num_cat/__init__.py +19 -0
  34. plotify_charts-0.1.0/plotify/num_cat/box_plot_by_group.py +110 -0
  35. plotify_charts-0.1.0/plotify/num_cat/grouped_bar_plot.py +110 -0
  36. plotify_charts-0.1.0/plotify/num_cat/grouped_scatter.py +105 -0
  37. plotify_charts-0.1.0/plotify/num_cat/stacked_bar_plot.py +117 -0
  38. plotify_charts-0.1.0/plotify/numerical/__init__.py +21 -0
  39. plotify_charts-0.1.0/plotify/numerical/boxplot.py +157 -0
  40. plotify_charts-0.1.0/plotify/numerical/connected_scatter_plot.py +120 -0
  41. plotify_charts-0.1.0/plotify/numerical/density_plot.py +184 -0
  42. plotify_charts-0.1.0/plotify/numerical/scatter_plot.py +140 -0
  43. plotify_charts-0.1.0/plotify/numerical/violin_plot.py +141 -0
  44. plotify_charts-0.1.0/plotify/theme.py +297 -0
  45. plotify_charts-0.1.0/plotify/timeseries/__init__.py +13 -0
  46. plotify_charts-0.1.0/plotify/timeseries/area_chart.py +89 -0
  47. plotify_charts-0.1.0/plotify/timeseries/line_chart.py +110 -0
  48. plotify_charts-0.1.0/plotify/timeseries/stacked_area_chart.py +133 -0
  49. plotify_charts-0.1.0/plotify/timeseries/stream_graph.py +116 -0
  50. plotify_charts-0.1.0/pyproject.toml +75 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kazi1318914 <mahin.kkgb.km@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,226 @@
1
+ Metadata-Version: 2.3
2
+ Name: plotify-charts
3
+ Version: 0.1.0
4
+ Summary: A Python plotting package with a dual Seaborn/Matplotlib + Plotly backend.
5
+ License: MIT
6
+ Keywords: plotting,visualization,dataviz,matplotlib,plotly,seaborn,charts
7
+ Author: Kazi1318914
8
+ Author-email: mahin.kkgb.km@gmail.com
9
+ Requires-Python: >=3.10,<3.13
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
20
+ Classifier: Topic :: Scientific/Engineering :: Visualization
21
+ Provides-Extra: full
22
+ Provides-Extra: maps
23
+ Requires-Dist: circlify (>=0.15)
24
+ Requires-Dist: geopandas (>=0.14) ; extra == "maps" or extra == "full"
25
+ Requires-Dist: kaleido (==0.2.1)
26
+ Requires-Dist: matplotlib (>=3.7)
27
+ Requires-Dist: matplotlib-venn (>=0.11)
28
+ Requires-Dist: networkx (>=3.1)
29
+ Requires-Dist: numpy (>=1.24)
30
+ Requires-Dist: pandas (>=2.0)
31
+ Requires-Dist: plotly (>=5.18)
32
+ Requires-Dist: scipy (>=1.10)
33
+ Requires-Dist: seaborn (>=0.13)
34
+ Requires-Dist: squarify (>=0.4.3)
35
+ Requires-Dist: statsmodels (>=0.14)
36
+ Requires-Dist: wordcloud (>=1.9)
37
+ Project-URL: Homepage, https://github.com/Kazi1318914/Plotify
38
+ Project-URL: Repository, https://github.com/Kazi1318914/Plotify
39
+ Description-Content-Type: text/markdown
40
+
41
+ # Plotify
42
+
43
+ Plotify is a Python plotting package built around two ideas:
44
+
45
+ 1. **Auto-pick** — given a dataframe and column names, Plotify infers the
46
+ right chart from the data shape and types. No need to remember which
47
+ function to call.
48
+ 2. **Publication-ready by default** — every chart ships with a
49
+ colourblind-safe palette, smart tick formatting (1.2K, 3.4M),
50
+ minimalist spines, and consistent typography on both backends.
51
+
52
+ Every plot can render on either Seaborn/Matplotlib (static images) or
53
+ Plotly (interactive HTML).
54
+
55
+ The chart catalogue and category split (Numerical, Categoric, Num & Cat,
56
+ Time series, Network, Maps) are inspired by
57
+ [data-to-viz.com](https://www.data-to-viz.com/).
58
+
59
+ ## Demo notebooks
60
+
61
+ The fastest way to see what Plotify can do — runnable notebooks under
62
+ [`notebooks/`](notebooks/) with every chart class rendered on both backends:
63
+
64
+ - [`00_quickstart.ipynb`](notebooks/00_quickstart.ipynb) — `auto`, `suggest`, themes
65
+ - [`01_numerical.ipynb`](notebooks/01_numerical.ipynb) — Boxplot, Density, Violin, Scatter, ConnectedScatter
66
+ - [`02_categorical.ipynb`](notebooks/02_categorical.ipynb) — all 12 categoric charts
67
+ - [`03_num_cat.ipynb`](notebooks/03_num_cat.ipynb) — GroupedBar, StackedBar, GroupedScatter, BoxPlotByGroup
68
+ - [`04_timeseries.ipynb`](notebooks/04_timeseries.ipynb) — Line, Area, StackedArea, StreamGraph
69
+ - [`05_network.ipynb`](notebooks/05_network.ipynb) — Network, Chord, Sankey, Arc, HierarchicalEdgeBundling
70
+ - [`06_maps.ipynb`](notebooks/06_maps.ipynb) — Choropleth, Bubble, Hexbin, Cartogram, Connection
71
+
72
+ Outputs are committed, so the notebooks render fully on GitHub without
73
+ running them.
74
+
75
+ ## Two-line example
76
+
77
+ ```python
78
+ import pandas as pd, plotify
79
+
80
+ df = pd.DataFrame({
81
+ "date": pd.date_range("2024-01-01", periods=12, freq="MS"),
82
+ "sales": [120, 140, 90, 200, 220, 260, 240, 310, 280, 330, 360, 410],
83
+ "region": ["North"] * 6 + ["South"] * 6,
84
+ })
85
+
86
+ plotify.auto(df, x="date", y="sales", color="region", backend="plotly")\
87
+ .save_plot("sales.html")
88
+ ```
89
+
90
+ `plotify.auto` looks at the dtypes (datetime, numeric, low-cardinality
91
+ group), picks `LineChart`, and returns a beautifully themed figure.
92
+
93
+ ## What `auto` actually picks
94
+
95
+ ```python
96
+ plotify.suggest(df, x="date", y="sales", color="region")
97
+ # → [Suggestion(LineChart, score=0.96, reason="datetime x + numeric y + low-cardinality group → multi-series line chart"),
98
+ # Suggestion(StackedAreaChart, score=0.72, reason="stacked area variant for compositional time series")]
99
+ ```
100
+
101
+ Suggestions come ranked, each with a one-line reason — useful for
102
+ debugging or for showing the user *why* a chart was picked.
103
+
104
+ You can also pass an `intent` to override the rules:
105
+
106
+ ```python
107
+ plotify.auto(df, x="region", y="sales", intent="distribution")
108
+ # → Violinplot
109
+ ```
110
+
111
+ ## Themes
112
+
113
+ `plotify.theme` controls the look of every chart on both backends.
114
+
115
+ ```python
116
+ import plotify
117
+
118
+ plotify.theme.get_current().name # "publication" — applied automatically
119
+ plotify.theme.set("none") # opt out, use library defaults
120
+ plotify.theme.register(plotify.theme.Theme(name="brand", palette=("#FF1493", "#00CED1")))
121
+ plotify.theme.set("brand")
122
+ ```
123
+
124
+ ## Package structure
125
+
126
+ ```
127
+ plotify/
128
+ ├── base.py # BasePlot — backend dispatch + save
129
+ ├── numerical/ # Boxplot, DensityPlot, Violinplot, ScatterPlot, ConnectedScatterPlot
130
+ ├── categorical/ # BarPlot, PieChart, Treemap, Sunburst, Venn, Dendrogram, etc. (12)
131
+ ├── num_cat/ # GroupedBarPlot, StackedBarPlot, GroupedScatter, BoxPlotByGroup
132
+ ├── timeseries/ # LineChart, AreaChart, StackedAreaChart, StreamGraph
133
+ ├── network/ # NetworkDiagram, ChordDiagram, SankeyDiagram, ArcDiagram, HierarchicalEdgeBundling
134
+ └── maps/ # ChoroplethMap, BubbleMap, HexbinMap, Cartogram, ConnectionMap
135
+ ```
136
+
137
+ ## Installation
138
+
139
+ ```bash
140
+ pip install plotify-charts # PyPI distribution name
141
+ pip install plotify-charts[maps] # adds geopandas for ChoroplethMap's seaborn path
142
+ pip install plotify-charts[full] # all optional extras
143
+ ```
144
+
145
+ The Python import name is `plotify` regardless of which install variant
146
+ you pick:
147
+
148
+ ```python
149
+ import plotify
150
+ ```
151
+
152
+ If you've cloned the repo for development, install with Poetry instead:
153
+
154
+ ```bash
155
+ poetry install --with dev --extras full
156
+ ```
157
+
158
+ ## Usage
159
+
160
+ ```python
161
+ import pandas as pd
162
+ from plotify.numerical import Boxplot
163
+ from plotify.categorical import BarPlot, PieChart
164
+ from plotify.timeseries import LineChart
165
+ from plotify.network import SankeyDiagram
166
+
167
+ df = pd.DataFrame({"cat": list("AAABBB"), "val": [1, 2, 3, 4, 5, 6]})
168
+
169
+ # Seaborn/Matplotlib backend → static image.
170
+ Boxplot(df, x="cat", y="val", backend="seaborn").save_plot("box.png")
171
+
172
+ # Plotly backend → interactive HTML (or static image via kaleido).
173
+ BarPlot(df, x="cat", y="val", backend="plotly").save_plot("bar.html")
174
+ PieChart(df, names="cat", values="val", backend="plotly").save_plot("pie.html")
175
+
176
+ # Sankey flow with explicit source/target/value lists.
177
+ SankeyDiagram(
178
+ source=[0, 1, 0],
179
+ target=[2, 2, 3],
180
+ value=[8, 4, 2],
181
+ labels=["A", "B", "C", "D"],
182
+ backend="plotly",
183
+ ).save_plot("sankey.html")
184
+ ```
185
+
186
+ Every plot class accepts `backend="seaborn"` (default) or `backend="plotly"`.
187
+ A few classes only support one backend — `WordCloudPlot`, `VennDiagram`,
188
+ `CircularPacking`, `StreamGraph`, `ChordDiagram`, `ArcDiagram`,
189
+ `HierarchicalEdgeBundling`, and `Cartogram` are Seaborn-only because Plotly
190
+ has no native equivalent. Requesting an unsupported backend raises a
191
+ `ValueError` at construction time.
192
+
193
+ ## Chart catalogue (all implemented)
194
+
195
+ | Category | Classes |
196
+ |---|---|
197
+ | Numerical | `Boxplot`, `DensityPlot`, `Violinplot`, `ScatterPlot`, `ConnectedScatterPlot` |
198
+ | Categoric | `BarPlot`, `LollipopChart`, `RadarChart`, `ParallelCoordinates`, `WordCloudPlot`, `PieChart`, `DoughnutChart`, `Treemap`, `CircularPacking`, `SunburstDiagram`, `VennDiagram`, `Dendrogram` |
199
+ | Num & Cat | `GroupedBarPlot`, `StackedBarPlot`, `GroupedScatter`, `BoxPlotByGroup` |
200
+ | Time series | `LineChart`, `AreaChart`, `StackedAreaChart`, `StreamGraph` |
201
+ | Network | `NetworkDiagram`, `ChordDiagram`, `SankeyDiagram`, `ArcDiagram`, `HierarchicalEdgeBundling` |
202
+ | Maps | `ChoroplethMap`, `BubbleMap`, `HexbinMap`, `Cartogram`, `ConnectionMap` |
203
+
204
+ ## Development
205
+
206
+ Run the test suite:
207
+
208
+ ```bash
209
+ poetry run pytest
210
+ ```
211
+
212
+ The notebooks under [`notebooks/`](notebooks/) are **generated** from
213
+ [`scripts/build_notebooks.py`](scripts/build_notebooks.py) — please don't
214
+ hand-edit them. After changing an API or a chart class, rebuild and
215
+ re-execute in a single step:
216
+
217
+ ```bash
218
+ python scripts/build_notebooks.py --execute
219
+ ```
220
+
221
+ The `--execute` flag runs each notebook via `jupyter nbconvert` so the
222
+ rendered outputs are embedded in the committed `.ipynb` files. The script
223
+ sets `PYTHONPATH` to the repo root automatically, so it works without
224
+ pip-installing the package.
225
+
226
+
@@ -0,0 +1,185 @@
1
+ # Plotify
2
+
3
+ Plotify is a Python plotting package built around two ideas:
4
+
5
+ 1. **Auto-pick** — given a dataframe and column names, Plotify infers the
6
+ right chart from the data shape and types. No need to remember which
7
+ function to call.
8
+ 2. **Publication-ready by default** — every chart ships with a
9
+ colourblind-safe palette, smart tick formatting (1.2K, 3.4M),
10
+ minimalist spines, and consistent typography on both backends.
11
+
12
+ Every plot can render on either Seaborn/Matplotlib (static images) or
13
+ Plotly (interactive HTML).
14
+
15
+ The chart catalogue and category split (Numerical, Categoric, Num & Cat,
16
+ Time series, Network, Maps) are inspired by
17
+ [data-to-viz.com](https://www.data-to-viz.com/).
18
+
19
+ ## Demo notebooks
20
+
21
+ The fastest way to see what Plotify can do — runnable notebooks under
22
+ [`notebooks/`](notebooks/) with every chart class rendered on both backends:
23
+
24
+ - [`00_quickstart.ipynb`](notebooks/00_quickstart.ipynb) — `auto`, `suggest`, themes
25
+ - [`01_numerical.ipynb`](notebooks/01_numerical.ipynb) — Boxplot, Density, Violin, Scatter, ConnectedScatter
26
+ - [`02_categorical.ipynb`](notebooks/02_categorical.ipynb) — all 12 categoric charts
27
+ - [`03_num_cat.ipynb`](notebooks/03_num_cat.ipynb) — GroupedBar, StackedBar, GroupedScatter, BoxPlotByGroup
28
+ - [`04_timeseries.ipynb`](notebooks/04_timeseries.ipynb) — Line, Area, StackedArea, StreamGraph
29
+ - [`05_network.ipynb`](notebooks/05_network.ipynb) — Network, Chord, Sankey, Arc, HierarchicalEdgeBundling
30
+ - [`06_maps.ipynb`](notebooks/06_maps.ipynb) — Choropleth, Bubble, Hexbin, Cartogram, Connection
31
+
32
+ Outputs are committed, so the notebooks render fully on GitHub without
33
+ running them.
34
+
35
+ ## Two-line example
36
+
37
+ ```python
38
+ import pandas as pd, plotify
39
+
40
+ df = pd.DataFrame({
41
+ "date": pd.date_range("2024-01-01", periods=12, freq="MS"),
42
+ "sales": [120, 140, 90, 200, 220, 260, 240, 310, 280, 330, 360, 410],
43
+ "region": ["North"] * 6 + ["South"] * 6,
44
+ })
45
+
46
+ plotify.auto(df, x="date", y="sales", color="region", backend="plotly")\
47
+ .save_plot("sales.html")
48
+ ```
49
+
50
+ `plotify.auto` looks at the dtypes (datetime, numeric, low-cardinality
51
+ group), picks `LineChart`, and returns a beautifully themed figure.
52
+
53
+ ## What `auto` actually picks
54
+
55
+ ```python
56
+ plotify.suggest(df, x="date", y="sales", color="region")
57
+ # → [Suggestion(LineChart, score=0.96, reason="datetime x + numeric y + low-cardinality group → multi-series line chart"),
58
+ # Suggestion(StackedAreaChart, score=0.72, reason="stacked area variant for compositional time series")]
59
+ ```
60
+
61
+ Suggestions come ranked, each with a one-line reason — useful for
62
+ debugging or for showing the user *why* a chart was picked.
63
+
64
+ You can also pass an `intent` to override the rules:
65
+
66
+ ```python
67
+ plotify.auto(df, x="region", y="sales", intent="distribution")
68
+ # → Violinplot
69
+ ```
70
+
71
+ ## Themes
72
+
73
+ `plotify.theme` controls the look of every chart on both backends.
74
+
75
+ ```python
76
+ import plotify
77
+
78
+ plotify.theme.get_current().name # "publication" — applied automatically
79
+ plotify.theme.set("none") # opt out, use library defaults
80
+ plotify.theme.register(plotify.theme.Theme(name="brand", palette=("#FF1493", "#00CED1")))
81
+ plotify.theme.set("brand")
82
+ ```
83
+
84
+ ## Package structure
85
+
86
+ ```
87
+ plotify/
88
+ ├── base.py # BasePlot — backend dispatch + save
89
+ ├── numerical/ # Boxplot, DensityPlot, Violinplot, ScatterPlot, ConnectedScatterPlot
90
+ ├── categorical/ # BarPlot, PieChart, Treemap, Sunburst, Venn, Dendrogram, etc. (12)
91
+ ├── num_cat/ # GroupedBarPlot, StackedBarPlot, GroupedScatter, BoxPlotByGroup
92
+ ├── timeseries/ # LineChart, AreaChart, StackedAreaChart, StreamGraph
93
+ ├── network/ # NetworkDiagram, ChordDiagram, SankeyDiagram, ArcDiagram, HierarchicalEdgeBundling
94
+ └── maps/ # ChoroplethMap, BubbleMap, HexbinMap, Cartogram, ConnectionMap
95
+ ```
96
+
97
+ ## Installation
98
+
99
+ ```bash
100
+ pip install plotify-charts # PyPI distribution name
101
+ pip install plotify-charts[maps] # adds geopandas for ChoroplethMap's seaborn path
102
+ pip install plotify-charts[full] # all optional extras
103
+ ```
104
+
105
+ The Python import name is `plotify` regardless of which install variant
106
+ you pick:
107
+
108
+ ```python
109
+ import plotify
110
+ ```
111
+
112
+ If you've cloned the repo for development, install with Poetry instead:
113
+
114
+ ```bash
115
+ poetry install --with dev --extras full
116
+ ```
117
+
118
+ ## Usage
119
+
120
+ ```python
121
+ import pandas as pd
122
+ from plotify.numerical import Boxplot
123
+ from plotify.categorical import BarPlot, PieChart
124
+ from plotify.timeseries import LineChart
125
+ from plotify.network import SankeyDiagram
126
+
127
+ df = pd.DataFrame({"cat": list("AAABBB"), "val": [1, 2, 3, 4, 5, 6]})
128
+
129
+ # Seaborn/Matplotlib backend → static image.
130
+ Boxplot(df, x="cat", y="val", backend="seaborn").save_plot("box.png")
131
+
132
+ # Plotly backend → interactive HTML (or static image via kaleido).
133
+ BarPlot(df, x="cat", y="val", backend="plotly").save_plot("bar.html")
134
+ PieChart(df, names="cat", values="val", backend="plotly").save_plot("pie.html")
135
+
136
+ # Sankey flow with explicit source/target/value lists.
137
+ SankeyDiagram(
138
+ source=[0, 1, 0],
139
+ target=[2, 2, 3],
140
+ value=[8, 4, 2],
141
+ labels=["A", "B", "C", "D"],
142
+ backend="plotly",
143
+ ).save_plot("sankey.html")
144
+ ```
145
+
146
+ Every plot class accepts `backend="seaborn"` (default) or `backend="plotly"`.
147
+ A few classes only support one backend — `WordCloudPlot`, `VennDiagram`,
148
+ `CircularPacking`, `StreamGraph`, `ChordDiagram`, `ArcDiagram`,
149
+ `HierarchicalEdgeBundling`, and `Cartogram` are Seaborn-only because Plotly
150
+ has no native equivalent. Requesting an unsupported backend raises a
151
+ `ValueError` at construction time.
152
+
153
+ ## Chart catalogue (all implemented)
154
+
155
+ | Category | Classes |
156
+ |---|---|
157
+ | Numerical | `Boxplot`, `DensityPlot`, `Violinplot`, `ScatterPlot`, `ConnectedScatterPlot` |
158
+ | Categoric | `BarPlot`, `LollipopChart`, `RadarChart`, `ParallelCoordinates`, `WordCloudPlot`, `PieChart`, `DoughnutChart`, `Treemap`, `CircularPacking`, `SunburstDiagram`, `VennDiagram`, `Dendrogram` |
159
+ | Num & Cat | `GroupedBarPlot`, `StackedBarPlot`, `GroupedScatter`, `BoxPlotByGroup` |
160
+ | Time series | `LineChart`, `AreaChart`, `StackedAreaChart`, `StreamGraph` |
161
+ | Network | `NetworkDiagram`, `ChordDiagram`, `SankeyDiagram`, `ArcDiagram`, `HierarchicalEdgeBundling` |
162
+ | Maps | `ChoroplethMap`, `BubbleMap`, `HexbinMap`, `Cartogram`, `ConnectionMap` |
163
+
164
+ ## Development
165
+
166
+ Run the test suite:
167
+
168
+ ```bash
169
+ poetry run pytest
170
+ ```
171
+
172
+ The notebooks under [`notebooks/`](notebooks/) are **generated** from
173
+ [`scripts/build_notebooks.py`](scripts/build_notebooks.py) — please don't
174
+ hand-edit them. After changing an API or a chart class, rebuild and
175
+ re-execute in a single step:
176
+
177
+ ```bash
178
+ python scripts/build_notebooks.py --execute
179
+ ```
180
+
181
+ The `--execute` flag runs each notebook via `jupyter nbconvert` so the
182
+ rendered outputs are embedded in the committed `.ipynb` files. The script
183
+ sets `PYTHONPATH` to the repo root automatically, so it works without
184
+ pip-installing the package.
185
+
@@ -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
+ ]
@@ -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([])