kx-plot 0.6.0__tar.gz → 0.7.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.
- {kx_plot-0.6.0 → kx_plot-0.7.0}/CHANGELOG.md +15 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/PKG-INFO +22 -7
- {kx_plot-0.6.0 → kx_plot-0.7.0}/README.md +21 -6
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/__init__.py +22 -8
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_plot.py +8 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_spec.py +2 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_stats.py +20 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_theme.py +60 -6
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_util.py +65 -0
- kx_plot-0.7.0/kx/data/regression.csv +501 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/kinds/basic.py +156 -29
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/kinds/dist.py +37 -3
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/LICENCES.md +18 -8
- kx_plot-0.7.0/kx/styles/colorblind.mplstyle +20 -0
- kx_plot-0.7.0/kx/styles/minimal.mplstyle +26 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/LICENCES.md +90 -12
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/dark2.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/ibm.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/okabe.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/paired.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/petroff10.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/petroff6.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/petroff8.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/set1.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/set2.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/tab10.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/tab20.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/tableaucb.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/tolbright.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/tolhc.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/tollight.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/tolmc.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/palettes/tolvibrant.txt +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/pyproject.toml +1 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_basic.py +69 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_data.py +3 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_dist.py +58 -1
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_flags.py +192 -2
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_stats.py +26 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_theme.py +122 -0
- kx_plot-0.6.0/kx/data/regression.csv +0 -501
- {kx_plot-0.6.0 → kx_plot-0.7.0}/.gitignore +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/LICENSE +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_cramers.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_data.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_embed.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_evaluate.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_files.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_grid.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_image.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_metrics.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/_save.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/binary.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/cloud.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/curves.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/daily.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/dists.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/embedding.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/history.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/importance.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/monthly.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/multiclass.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/passengers.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/shapes.npz +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/data/waves.csv +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/kinds/__init__.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/kinds/image.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/kinds/ml.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/kinds/table.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/balance.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/bam.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/batlow.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/cork.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/davos.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/deep.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/haline.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/hawaii.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/lipari.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/oslo.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/roma.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/romaO.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/thermal.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/cmaps/vik.txt +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/dark.mplstyle +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/light.mplstyle +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/paper.mplstyle +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/poster.mplstyle +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/science.mplstyle +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/talk.mplstyle +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/kx/styles/thesis.mplstyle +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/conftest.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/helpers.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_api.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_image.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_ml.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_plot.py +0 -0
- {kx_plot-0.6.0 → kx_plot-0.7.0}/tests/test_table.py +0 -0
|
@@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.7.0] - 2026-11-24
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Flag** `ci` (`line`, `step`): the mean at each x with a bootstrap 95% band; `n_boot=`, `seed=`.
|
|
14
|
+
- `ci` on `bar` and `barh`: the mean per category with bootstrap 95% error bars.
|
|
15
|
+
- **Plot kind** `errbar`: the mean per series or `by=` group with a bootstrap 95% interval; `sd`, `ann`, `sig`.
|
|
16
|
+
- **Flag** `endlab` (`line`, `step`, `band`, `area`): each line's name at its right end instead of a legend.
|
|
17
|
+
- **Plot kind** `lollipop`: a dot per category on a stem from 0, or a dumbbell from `y` to `z`; `sort`, `ann`.
|
|
18
|
+
- `kx.register(name, colors, cmap=False)`: a palette or colormap of your own for the session.
|
|
19
|
+
- **Theme** `minimal`: no box or tick marks, a light grid along the values only.
|
|
20
|
+
- **Theme** `colorblind`: Okabe-Ito without yellow, each colour with its own linestyle; `cividis` colormap.
|
|
21
|
+
|
|
9
22
|
## [0.6.0] - 2026-11-04
|
|
10
23
|
|
|
11
24
|
### Added
|
|
@@ -325,7 +338,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
325
338
|
- `kx.use`, `kx.show`, `kx.source`, `kx.grammar`, `kx.load` and the demo CSVs
|
|
326
339
|
- a workflow that publishes the dataset to Kaggle
|
|
327
340
|
|
|
328
|
-
[Unreleased]: https://github.com/vhrabar/kx-plot/compare/v0.
|
|
341
|
+
[Unreleased]: https://github.com/vhrabar/kx-plot/compare/v0.7.0...HEAD
|
|
342
|
+
[0.7.0]: https://github.com/vhrabar/kx-plot/compare/v0.6.0...v0.7.0
|
|
329
343
|
[0.6.0]: https://github.com/vhrabar/kx-plot/compare/v0.5.0...v0.6.0
|
|
330
344
|
[0.5.0]: https://github.com/vhrabar/kx-plot/compare/v0.4.0...v0.5.0
|
|
331
345
|
[0.4.0]: https://github.com/vhrabar/kx-plot/compare/v0.3.0...v0.4.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: kx-plot
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: One-line matplotlib plots, themes and model-evaluation charts for notebooks and scripts, Kaggle-friendly
|
|
5
5
|
Project-URL: Homepage, https://github.com/vhrabar/kx-plot
|
|
6
6
|
Project-URL: Issues, https://github.com/vhrabar/kx-plot/issues
|
|
@@ -88,16 +88,16 @@ kx.plot(df.value, spec='box', by=df.group) # one box per group (also rid
|
|
|
88
88
|
|
|
89
89
|
| Token | Values |
|
|
90
90
|
|-------|-----------------------------------------------------------------------------------------------|
|
|
91
|
-
| kind | `line` `step` `area` `band` `scatter` `bar` `barh` `hist` `kde` `ridge` `ecdf`
|
|
92
|
-
| | `
|
|
93
|
-
| | `parallel` `pair` `cluster` `mosaic` `treemap` `sunburst`
|
|
91
|
+
| kind | `line` `step` `area` `band` `scatter` `bar` `barh` `lollipop` `hist` `kde` `ridge` `ecdf` |
|
|
92
|
+
| | `box` `violin` `strip` `errbar` `qq` `count` `crosstab` `hexbin` `heat` `missing` `nullmap` |
|
|
93
|
+
| | `pie` `donut` `radar` `parallel` `pair` `cluster` `mosaic` `treemap` `sunburst` |
|
|
94
94
|
| | ML: `cm` `roc` `pr` `calib` `proba` `thresh` `gain` `lift` `pva` `resid` `imp` `loss` |
|
|
95
95
|
| | `lcurve` `vcurve` `elbow` `embed` |
|
|
96
96
|
| | Images: `imgrid` `meanimg` `colorhist` `imhist` `segmask` `saliency` `miscls` |
|
|
97
|
-
| theme | `dark` `light` `paper` `science` `talk` `poster` `thesis`
|
|
97
|
+
| theme | `dark` `light` `minimal` `colorblind` `paper` `science` `talk` `poster` `thesis` |
|
|
98
98
|
| flags | `grid` `leg` `legout` `tight` `rot` `wrap` `logx` `logy` `logxy` `symlogy` `zero` `eq` `pct` |
|
|
99
|
-
| | `si` `facet`; per kind: `stack` `norm` `cum` `date` `mk` `
|
|
100
|
-
| | `sym` `logc` `corr` `all` `diag` `fit` `best` `raw` `sig`
|
|
99
|
+
| | `si` `facet`; per kind: `stack` `norm` `cum` `date` `mk` `endlab` `ci` `sort` `ann` `mean` |
|
|
100
|
+
| | `median` `sd` `nocb` `sym` `logc` `corr` `all` `diag` `fit` `best` `raw` `sig` |
|
|
101
101
|
|
|
102
102
|
`stack` works with `area`, `bar`, `barh` and `hist`. `norm` is a 100% stack for `area` and a
|
|
103
103
|
density (area 1) for `hist`. `cum` makes `hist` cumulative; `hist-norm-cum` is the CDF.
|
|
@@ -108,6 +108,20 @@ its slope and R² in the legend (one line per group with a categorical `z`).
|
|
|
108
108
|
`sig` on `box` and `violin` writes the Kruskal-Wallis p and brackets the pairs that differ, with stars (`ann`: the
|
|
109
109
|
p-values), Holm-corrected.
|
|
110
110
|
|
|
111
|
+
### Uncertainty and labels
|
|
112
|
+
|
|
113
|
+
`ci` draws the mean of the rows at each x with a bootstrap 95% interval: a band on `line` and `step`, error bars
|
|
114
|
+
on `bar` and `barh` (`n_boot=` resamples, 1000; `seed=`, 0). `errbar` is the mean and interval per series or
|
|
115
|
+
`by=` group, `sd` for mean ± one standard deviation instead, `sig` for the tests as on `box`.
|
|
116
|
+
`endlab` writes each line's name at its right end instead of a legend, on `line`, `step`, `band` and `area`.
|
|
117
|
+
`lollipop` is a dot per category on a stem from 0, or with `z` a dumbbell from `y` to `z` (`sort` by the change).
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
kx.plot(df, 'month', 'temp', 'line-ci-endlab') # each month's mean, a 95% band, the name at the end
|
|
121
|
+
kx.plot(df, 'fare', spec='errbar-sig', by='pclass') # mean and interval per class, with the tests
|
|
122
|
+
kx.plot(df, 'city', 'before', 'after', 'lollipop-sort')
|
|
123
|
+
```
|
|
124
|
+
|
|
111
125
|
`facet` draws a plot once per value of a column, `kx.plot(df, 'pclass', 'port', 'crosstab-facet', facet='sex')`,
|
|
112
126
|
with every category in every panel, shared axes, and one colour scale and colorbar for the colour kinds.
|
|
113
127
|
|
|
@@ -228,6 +242,7 @@ other cycled properties (such as `paper`'s linestyles) stay.
|
|
|
228
242
|
| `ibm` | IBM Design Colors |
|
|
229
243
|
|
|
230
244
|
`kx.palette('okabe')` returns the hex codes. A list of colours works too: `palette=['#264653', '#e9c46a']`.
|
|
245
|
+
`kx.register('brand', colors)` adds a named palette for the session, `cmap=True` a colourmap through the colours.
|
|
231
246
|
|
|
232
247
|
## Colourmaps
|
|
233
248
|
|
|
@@ -47,16 +47,16 @@ kx.plot(df.value, spec='box', by=df.group) # one box per group (also rid
|
|
|
47
47
|
|
|
48
48
|
| Token | Values |
|
|
49
49
|
|-------|-----------------------------------------------------------------------------------------------|
|
|
50
|
-
| kind | `line` `step` `area` `band` `scatter` `bar` `barh` `hist` `kde` `ridge` `ecdf`
|
|
51
|
-
| | `
|
|
52
|
-
| | `parallel` `pair` `cluster` `mosaic` `treemap` `sunburst`
|
|
50
|
+
| kind | `line` `step` `area` `band` `scatter` `bar` `barh` `lollipop` `hist` `kde` `ridge` `ecdf` |
|
|
51
|
+
| | `box` `violin` `strip` `errbar` `qq` `count` `crosstab` `hexbin` `heat` `missing` `nullmap` |
|
|
52
|
+
| | `pie` `donut` `radar` `parallel` `pair` `cluster` `mosaic` `treemap` `sunburst` |
|
|
53
53
|
| | ML: `cm` `roc` `pr` `calib` `proba` `thresh` `gain` `lift` `pva` `resid` `imp` `loss` |
|
|
54
54
|
| | `lcurve` `vcurve` `elbow` `embed` |
|
|
55
55
|
| | Images: `imgrid` `meanimg` `colorhist` `imhist` `segmask` `saliency` `miscls` |
|
|
56
|
-
| theme | `dark` `light` `paper` `science` `talk` `poster` `thesis`
|
|
56
|
+
| theme | `dark` `light` `minimal` `colorblind` `paper` `science` `talk` `poster` `thesis` |
|
|
57
57
|
| flags | `grid` `leg` `legout` `tight` `rot` `wrap` `logx` `logy` `logxy` `symlogy` `zero` `eq` `pct` |
|
|
58
|
-
| | `si` `facet`; per kind: `stack` `norm` `cum` `date` `mk` `
|
|
59
|
-
| | `sym` `logc` `corr` `all` `diag` `fit` `best` `raw` `sig`
|
|
58
|
+
| | `si` `facet`; per kind: `stack` `norm` `cum` `date` `mk` `endlab` `ci` `sort` `ann` `mean` |
|
|
59
|
+
| | `median` `sd` `nocb` `sym` `logc` `corr` `all` `diag` `fit` `best` `raw` `sig` |
|
|
60
60
|
|
|
61
61
|
`stack` works with `area`, `bar`, `barh` and `hist`. `norm` is a 100% stack for `area` and a
|
|
62
62
|
density (area 1) for `hist`. `cum` makes `hist` cumulative; `hist-norm-cum` is the CDF.
|
|
@@ -67,6 +67,20 @@ its slope and R² in the legend (one line per group with a categorical `z`).
|
|
|
67
67
|
`sig` on `box` and `violin` writes the Kruskal-Wallis p and brackets the pairs that differ, with stars (`ann`: the
|
|
68
68
|
p-values), Holm-corrected.
|
|
69
69
|
|
|
70
|
+
### Uncertainty and labels
|
|
71
|
+
|
|
72
|
+
`ci` draws the mean of the rows at each x with a bootstrap 95% interval: a band on `line` and `step`, error bars
|
|
73
|
+
on `bar` and `barh` (`n_boot=` resamples, 1000; `seed=`, 0). `errbar` is the mean and interval per series or
|
|
74
|
+
`by=` group, `sd` for mean ± one standard deviation instead, `sig` for the tests as on `box`.
|
|
75
|
+
`endlab` writes each line's name at its right end instead of a legend, on `line`, `step`, `band` and `area`.
|
|
76
|
+
`lollipop` is a dot per category on a stem from 0, or with `z` a dumbbell from `y` to `z` (`sort` by the change).
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
kx.plot(df, 'month', 'temp', 'line-ci-endlab') # each month's mean, a 95% band, the name at the end
|
|
80
|
+
kx.plot(df, 'fare', spec='errbar-sig', by='pclass') # mean and interval per class, with the tests
|
|
81
|
+
kx.plot(df, 'city', 'before', 'after', 'lollipop-sort')
|
|
82
|
+
```
|
|
83
|
+
|
|
70
84
|
`facet` draws a plot once per value of a column, `kx.plot(df, 'pclass', 'port', 'crosstab-facet', facet='sex')`,
|
|
71
85
|
with every category in every panel, shared axes, and one colour scale and colorbar for the colour kinds.
|
|
72
86
|
|
|
@@ -187,6 +201,7 @@ other cycled properties (such as `paper`'s linestyles) stay.
|
|
|
187
201
|
| `ibm` | IBM Design Colors |
|
|
188
202
|
|
|
189
203
|
`kx.palette('okabe')` returns the hex codes. A list of colours works too: `palette=['#264653', '#e9c46a']`.
|
|
204
|
+
`kx.register('brand', colors)` adds a named palette for the session, `cmap=True` a colourmap through the colours.
|
|
190
205
|
|
|
191
206
|
## Colourmaps
|
|
192
207
|
|
|
@@ -2,24 +2,25 @@
|
|
|
2
2
|
kx: tiny matplotlib helper.
|
|
3
3
|
|
|
4
4
|
Token grammar for kx.plot(spec): kind-theme-flag-flag-...
|
|
5
|
-
kind : line | step | area | band | scatter | bar | barh | hist | kde | ridge | ecdf | box | violin
|
|
6
|
-
| qq | heat | crosstab | count | missing | nullmap | hexbin | pie | donut | radar | parallel
|
|
7
|
-
| cluster | mosaic | treemap | sunburst
|
|
5
|
+
kind : line | step | area | band | scatter | bar | barh | lollipop | hist | kde | ridge | ecdf | box | violin
|
|
6
|
+
| strip | errbar | qq | heat | crosstab | count | missing | nullmap | hexbin | pie | donut | radar | parallel
|
|
7
|
+
| pair | cluster | mosaic | treemap | sunburst
|
|
8
8
|
| cm | roc | pr | calib | proba | thresh | gain | lift | pva | resid | imp | loss
|
|
9
9
|
| lcurve | vcurve | elbow | embed
|
|
10
10
|
| imgrid | meanimg | colorhist | imhist | segmask | saliency | miscls
|
|
11
11
|
theme : any file name in styles/
|
|
12
12
|
flags : grid | leg | legout | tight | rot | wrap | logx | logy | logxy | symlogy | zero | eq | pct | si | facet
|
|
13
|
-
and per kind: stack norm cum (bars, area, hist), date mk (lines), sort ann (bars, count),
|
|
13
|
+
and per kind: stack norm cum (bars, area, hist), date mk endlab (lines), sort ann (bars, count, lollipop),
|
|
14
|
+
ci (line, step, bar, barh),
|
|
14
15
|
stack norm (count),
|
|
15
|
-
mean median ann (distributions), sig (box, violin),
|
|
16
|
+
mean median ann (distributions), sig (box, violin, errbar), ann sd (errbar),
|
|
16
17
|
nocb sym logc (scatter, heat, hexbin, cluster), corr ann (heat, cluster),
|
|
17
18
|
norm ann nocb logc (crosstab), ann all (missing), sort (nullmap), diag (scatter, hexbin),
|
|
18
19
|
fit (scatter), norm ann nocb (cm), norm (proba), best (thresh, loss, elbow),
|
|
19
20
|
nocb sym logc (resid), ann sort (pie, donut), ann (mosaic, treemap, sunburst), raw (radar), mean (parallel),
|
|
20
21
|
std (meanimg), hsv map (colorhist), hsv (imhist), ann nocb sym logc (embed).
|
|
21
22
|
kx.grammar(kind) lists them.
|
|
22
|
-
by= : group labels for x, one series per group (kde, ridge, ecdf, box, violin, strip, qq, count);
|
|
23
|
+
by= : group labels for x, one series per group (kde, ridge, ecdf, box, violin, strip, errbar, qq, count);
|
|
23
24
|
for radar, parallel and pair a column of the table: kx.plot(df, 'radar', by='class')
|
|
24
25
|
images : image kinds take an (N, H, W[, C]) array or a list of arrays or file paths, labels as y:
|
|
25
26
|
kx.plot(images, labels, 'imgrid')
|
|
@@ -30,6 +31,7 @@ table : heat, cluster, missing, nullmap, loss, radar, parallel, pair take a who
|
|
|
30
31
|
|
|
31
32
|
Palettes (kx.use(theme, palette="okabe")): any file name in styles/palettes/
|
|
32
33
|
Colormaps (kx.use(theme, cmap="magma")): kx.cmaps()
|
|
34
|
+
kx.register("brand", colors): a palette (cmap=True: a colormap) of your own for this session, then as above.
|
|
33
35
|
with kx.context(theme, ...): the same as kx.use, for one block only.
|
|
34
36
|
kx.save("fig.png"): saves to /kaggle/working on Kaggle, the current folder elsewhere.
|
|
35
37
|
kx.load("passengers"): a demo table; kx.load("shapes"): a dict of image arrays. kx.datasets() lists them.
|
|
@@ -60,11 +62,23 @@ from ._metrics import pr_ap, roc_auc
|
|
|
60
62
|
from ._plot import plot
|
|
61
63
|
from ._save import save
|
|
62
64
|
from ._spec import COMMON_FLAGS, KINDS, Spec, all_flags, parse
|
|
63
|
-
from ._theme import
|
|
65
|
+
from ._theme import (
|
|
66
|
+
BREWER_CMAPS,
|
|
67
|
+
BUILTIN_CMAPS,
|
|
68
|
+
VENDORED_CMAPS,
|
|
69
|
+
cmaps,
|
|
70
|
+
context,
|
|
71
|
+
palette,
|
|
72
|
+
palettes,
|
|
73
|
+
register,
|
|
74
|
+
show,
|
|
75
|
+
styles,
|
|
76
|
+
use,
|
|
77
|
+
)
|
|
64
78
|
|
|
65
79
|
__all__ = ["BREWER_CMAPS", "BUILTIN_CMAPS", "VENDORED_CMAPS", "Spec", "__version__", "cmaps", "context", "cramers",
|
|
66
80
|
"datasets", "embed", "evaluate", "grammar", "grid", "load", "missing", "palette", "palettes", "parse",
|
|
67
|
-
"plot", "pr_ap", "roc_auc", "save", "show", "source", "styles", "use"]
|
|
81
|
+
"plot", "pr_ap", "register", "roc_auc", "save", "show", "source", "styles", "use"]
|
|
68
82
|
|
|
69
83
|
|
|
70
84
|
def _version() -> str:
|
|
@@ -192,7 +192,14 @@ def _column(df: pd.DataFrame, name: object) -> pd.Series:
|
|
|
192
192
|
def _common(ax: Axes, name: str, value_axis: str, flags: set[str]) -> None:
|
|
193
193
|
"""Flags every kind takes: legend, scales, value-axis format, ticks."""
|
|
194
194
|
values = ax.xaxis if value_axis == "x" else ax.yaxis
|
|
195
|
-
if "grid" in flags:
|
|
195
|
+
if "grid" in flags:
|
|
196
|
+
ax.grid(True)
|
|
197
|
+
elif plt.rcParams["axes.grid"]:
|
|
198
|
+
if ax.images:
|
|
199
|
+
ax.grid(False)
|
|
200
|
+
elif value_axis == "x" and plt.rcParams["axes.grid.axis"] == "y":
|
|
201
|
+
ax.grid(False, axis="y")
|
|
202
|
+
ax.grid(True, axis="x")
|
|
196
203
|
if flags & {"leg", "legout"} and ax.get_legend_handles_labels()[0]: # nothing labelled (scatter z): none
|
|
197
204
|
old = ax.get_legend()
|
|
198
205
|
outside = "legout" in flags or (name == "area" and "norm" in flags) # a 100% stack has no free corner
|
|
@@ -9,7 +9,8 @@ from ._theme import styles
|
|
|
9
9
|
COMMON_FLAGS = {"grid", "leg", "legout", "tight", "rot", "wrap", # handled by kx.plot for every kind
|
|
10
10
|
"logx", "logy", "logxy", "symlogy", "zero", "eq", "pct", "si", "facet"}
|
|
11
11
|
EXCLUSIVE = ({"logy", "logxy", "symlogy"}, {"logx", "logxy"}, {"zero", "logy"}, {"zero", "logxy"},
|
|
12
|
-
{"pct", "si"}, {"sym", "logc"}, {"corr", "logc"}
|
|
12
|
+
{"pct", "si"}, {"sym", "logc"}, {"corr", "logc"},
|
|
13
|
+
{"ci", "stack"}, {"endlab", "leg"}, {"endlab", "legout"}) # pairs that ask for opposite things
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
@dataclass(frozen=True)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Statistics for the significance, association and clustering kinds, in numpy with no scipy needed
|
|
2
|
+
Statistics for the interval, significance, association and clustering kinds, in numpy with no scipy needed
|
|
3
3
|
"""
|
|
4
4
|
import math
|
|
5
5
|
|
|
@@ -8,6 +8,7 @@ import pandas as pd
|
|
|
8
8
|
from numpy.typing import ArrayLike
|
|
9
9
|
|
|
10
10
|
MAX_LEAVES = 1000
|
|
11
|
+
BOOT_CELLS = 10_000_000
|
|
11
12
|
METHODS = ("single", "complete", "average", "ward")
|
|
12
13
|
|
|
13
14
|
|
|
@@ -62,6 +63,24 @@ def _gamma_q(a: float, x: float) -> float:
|
|
|
62
63
|
return math.exp(log_front) * h
|
|
63
64
|
|
|
64
65
|
|
|
66
|
+
def bootstrap(values: ArrayLike, n_boot: int = 1000, seed: int = 0) -> tuple[float, float]:
|
|
67
|
+
"""The percentile 95% interval of the mean: the 2.5th and 97.5th percentiles of n_boot means of resamples
|
|
68
|
+
drawn with replacement. NaNs are dropped; one value gives (v, v), none (nan, nan). The same seed gives the
|
|
69
|
+
same interval."""
|
|
70
|
+
if n_boot < 1:
|
|
71
|
+
raise ValueError(f"n_boot= must be at least 1, got {n_boot}")
|
|
72
|
+
v = np.asarray(values, dtype=float).ravel()
|
|
73
|
+
v = v[~np.isnan(v)]
|
|
74
|
+
if len(v) < 2:
|
|
75
|
+
return (float(v[0]), float(v[0])) if len(v) else (math.nan, math.nan)
|
|
76
|
+
rng = np.random.default_rng(seed)
|
|
77
|
+
rows = max(1, BOOT_CELLS // len(v)) # resamples per chunk, so a long series does not fill memory
|
|
78
|
+
means = np.concatenate([v[rng.integers(0, len(v), (min(rows, n_boot - i), len(v)))].mean(axis=1)
|
|
79
|
+
for i in range(0, n_boot, rows)])
|
|
80
|
+
lo, hi = np.percentile(means, [2.5, 97.5])
|
|
81
|
+
return float(lo), float(hi)
|
|
82
|
+
|
|
83
|
+
|
|
65
84
|
def chi2_sf(x: float, df: int) -> float:
|
|
66
85
|
"""P(X > x) for X chi-squared with df degrees of freedom."""
|
|
67
86
|
return _gamma_q(df / 2, x / 2)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"""Themes, palettes and colormaps: discovery, kx.use and kx.context."""
|
|
2
2
|
import contextlib
|
|
3
|
-
from collections.abc import Iterator
|
|
3
|
+
from collections.abc import Iterator, Sequence
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
import matplotlib as mpl
|
|
7
7
|
import matplotlib.pyplot as plt
|
|
8
|
-
from matplotlib.colors import ListedColormap
|
|
8
|
+
from matplotlib.colors import Colormap, LinearSegmentedColormap, ListedColormap, to_hex
|
|
9
9
|
|
|
10
10
|
from . import _files
|
|
11
11
|
|
|
@@ -17,6 +17,11 @@ BREWER_CMAPS = {"blues": "Blues", "greys": "Greys", "rdbu": "RdBu"}
|
|
|
17
17
|
VENDORED_CMAPS = ("thermal", "haline", "deep", "balance",
|
|
18
18
|
"batlow", "lipari", "hawaii", "oslo", "davos", "vik", "roma", "bam", "cork", "romaO")
|
|
19
19
|
|
|
20
|
+
# kx.register: name -> '#rrggbb' colours, for this session
|
|
21
|
+
_RUNTIME_PALETTES: dict[str, list[str]] = {}
|
|
22
|
+
# kx.register(cmap=True): names added to mpl.colormaps
|
|
23
|
+
_RUNTIME_CMAPS: set[str] = set()
|
|
24
|
+
|
|
20
25
|
|
|
21
26
|
def styles() -> list[str]:
|
|
22
27
|
"""List available theme names."""
|
|
@@ -31,8 +36,8 @@ def style_path(name: str) -> str:
|
|
|
31
36
|
|
|
32
37
|
|
|
33
38
|
def palettes() -> list[str]:
|
|
34
|
-
"""List available palette names."""
|
|
35
|
-
return _files.names("styles/palettes", ".txt")
|
|
39
|
+
"""List available palette names: the files in styles/palettes/ and those added with kx.register."""
|
|
40
|
+
return sorted({*_files.names("styles/palettes", ".txt"), *_RUNTIME_PALETTES})
|
|
36
41
|
|
|
37
42
|
|
|
38
43
|
def palette(name: str) -> list[str]:
|
|
@@ -42,6 +47,8 @@ def palette(name: str) -> list[str]:
|
|
|
42
47
|
|
|
43
48
|
def _read_palette(name: str) -> list[str]:
|
|
44
49
|
"""palette() under a name that kx.use's `palette` argument does not shadow."""
|
|
50
|
+
if name in _RUNTIME_PALETTES:
|
|
51
|
+
return list(_RUNTIME_PALETTES[name])
|
|
45
52
|
if name not in palettes():
|
|
46
53
|
raise ValueError(f"unknown palette {name!r}. Available: {palettes()}")
|
|
47
54
|
return _read_hex(_files.path("styles", "palettes", f"{name}.txt"))
|
|
@@ -73,8 +80,55 @@ _register_cmaps()
|
|
|
73
80
|
|
|
74
81
|
|
|
75
82
|
def cmaps() -> list[str]:
|
|
76
|
-
"""List supported colormap names that this matplotlib version has, plus the vendored ones
|
|
77
|
-
|
|
83
|
+
"""List supported colormap names that this matplotlib version has, plus the vendored ones and those added
|
|
84
|
+
with kx.register."""
|
|
85
|
+
names = (*BUILTIN_CMAPS, *BREWER_CMAPS, *VENDORED_CMAPS, *_RUNTIME_CMAPS)
|
|
86
|
+
return sorted({n for n in names if n in mpl.colormaps})
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def register(name: str, colors: Sequence[Any] | Colormap, cmap: bool = False) -> None:
|
|
90
|
+
"""Add a palette, or with cmap=True a colormap, for this session: kx.register('brand', ['#0b3d91', 'tab:red'])
|
|
91
|
+
colors: anything matplotlib reads as a colour ('#hex', names, RGB tuples); a Colormap is registered as a
|
|
92
|
+
colormap. A palette then works as kx.use(palette='brand'), a colormap as kx.use(cmap='brand') and 'brand_r'.
|
|
93
|
+
A name a shipped palette or a matplotlib colormap already has raises; registering the same name again
|
|
94
|
+
replaces it, so a notebook cell can run twice. To keep one, add a file to styles/palettes/ or styles/cmaps/."""
|
|
95
|
+
if not isinstance(name, str) or not name.strip() or name.endswith("_r"):
|
|
96
|
+
raise ValueError(f"register needs a name that does not end in '_r' (kept for reversed maps), got {name!r}")
|
|
97
|
+
if isinstance(colors, Colormap) or cmap:
|
|
98
|
+
_register_cmap(name, colors)
|
|
99
|
+
return
|
|
100
|
+
if name in _files.names("styles/palettes", ".txt"):
|
|
101
|
+
raise ValueError(f"palette {name!r} ships with kx; pick another name")
|
|
102
|
+
_RUNTIME_PALETTES[name] = _hexes(colors, least=1)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _register_cmap(name: str, colors: Sequence[Any] | Colormap) -> None:
|
|
106
|
+
"""kx.register with cmap=True: a copy of a Colormap, or a smooth map through the colours, in mpl.colormaps."""
|
|
107
|
+
if name in mpl.colormaps and name not in _RUNTIME_CMAPS:
|
|
108
|
+
raise ValueError(f"colormap {name!r} exists in matplotlib or kx; pick another name")
|
|
109
|
+
if isinstance(colors, Colormap):
|
|
110
|
+
new = colors.copy()
|
|
111
|
+
new.name = name
|
|
112
|
+
else:
|
|
113
|
+
new = LinearSegmentedColormap.from_list(name, _hexes(colors, least=2))
|
|
114
|
+
for old in (name, f"{name}_r"): # the old map, and a reversed copy kx.use made of it
|
|
115
|
+
if old in mpl.colormaps:
|
|
116
|
+
mpl.colormaps.unregister(old)
|
|
117
|
+
mpl.colormaps.register(new, name=name)
|
|
118
|
+
_RUNTIME_CMAPS.add(name)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _hexes(colors: Sequence[Any], least: int) -> list[str]:
|
|
122
|
+
"""colors as '#rrggbb', at least `least` of them; a bad colour raises naming it."""
|
|
123
|
+
if isinstance(colors, str) or len(colors) < least:
|
|
124
|
+
raise ValueError(f"register needs a list of at least {least} colours, got {colors!r}")
|
|
125
|
+
out = []
|
|
126
|
+
for c in colors:
|
|
127
|
+
try:
|
|
128
|
+
out.append(to_hex(c))
|
|
129
|
+
except (ValueError, TypeError):
|
|
130
|
+
raise ValueError(f"register: {c!r} is not a colour") from None
|
|
131
|
+
return out
|
|
78
132
|
|
|
79
133
|
|
|
80
134
|
def show(name: str) -> None:
|
|
@@ -73,3 +73,68 @@ def split(ax: Axes, rows: int, cols: int, projection: str | None = None, **kw: A
|
|
|
73
73
|
ax.remove()
|
|
74
74
|
cells = spec.subgridspec(rows, cols, **kw)
|
|
75
75
|
return np.array([fig.add_subplot(cells[r, c], projection=projection) for r in range(rows) for c in range(cols)])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
ENDLAB_GAP = 1.2
|
|
79
|
+
ENDLAB_PAD = 6
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class _Spread(mpl.artist.Artist):
|
|
83
|
+
"""endlab: draws nothing; drawn just before the labels (lowest zorder), it spaces them for the final limits,
|
|
84
|
+
scales and size, which are only known at draw time."""
|
|
85
|
+
|
|
86
|
+
def __init__(self, labels: list[mpl.text.Annotation]) -> None:
|
|
87
|
+
super().__init__()
|
|
88
|
+
self.labels = labels
|
|
89
|
+
self.set_in_layout(False)
|
|
90
|
+
self.set_zorder(-np.inf)
|
|
91
|
+
|
|
92
|
+
def draw(self, renderer: Any) -> None:
|
|
93
|
+
spread(self.labels)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def spread(labels: list[mpl.text.Annotation]) -> None:
|
|
97
|
+
"""Each label's vertical offset from its line's end, so labels are at least ENDLAB_GAP label heights apart:
|
|
98
|
+
overlapping labels merge into a block centred on where their lines end, until no blocks overlap."""
|
|
99
|
+
if not labels:
|
|
100
|
+
return
|
|
101
|
+
ax = labels[0].axes
|
|
102
|
+
to_pt = 72 / ax.figure.dpi
|
|
103
|
+
ends = np.array([ax.transData.transform((ax.viewLim.x0, float(a.xy[1])))[1] * to_pt
|
|
104
|
+
for a in labels]) # in points, where each line ends; y alone, x may be a category
|
|
105
|
+
gap = ENDLAB_GAP * max(a.get_fontsize() for a in labels)
|
|
106
|
+
blocks = [[i] for i in np.argsort(ends, kind="stable")] # bottom to top
|
|
107
|
+
|
|
108
|
+
def place(block: list[int]) -> np.ndarray:
|
|
109
|
+
return ends[block].mean() + gap * (np.arange(len(block)) - (len(block) - 1) / 2)
|
|
110
|
+
|
|
111
|
+
merged = True
|
|
112
|
+
while merged:
|
|
113
|
+
merged = False
|
|
114
|
+
for k in range(len(blocks) - 1):
|
|
115
|
+
if place(blocks[k])[-1] + gap > place(blocks[k + 1])[0]:
|
|
116
|
+
blocks[k:k + 2] = [blocks[k] + blocks[k + 1]]
|
|
117
|
+
merged = True
|
|
118
|
+
break
|
|
119
|
+
for block in blocks:
|
|
120
|
+
for i, at in zip(block, place(block), strict=True):
|
|
121
|
+
labels[i].xyann = (ENDLAB_PAD, at - ends[i])
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def endlabels(ax: Axes) -> list[mpl.text.Annotation]:
|
|
125
|
+
"""endlab: each labelled line's name at its last finite point, in its colour, instead of a legend."""
|
|
126
|
+
labels = []
|
|
127
|
+
for ln in ax.lines:
|
|
128
|
+
name = ln.get_label()
|
|
129
|
+
ys = np.asarray(ln.get_ydata(), dtype=float)
|
|
130
|
+
keep = np.flatnonzero(np.isfinite(ys))
|
|
131
|
+
if name.startswith("_") or not len(keep):
|
|
132
|
+
continue
|
|
133
|
+
xy = (np.asarray(ln.get_xdata())[keep[-1]], ys[keep[-1]])
|
|
134
|
+
labels.append(ax.annotate(name, xy, xytext=(ENDLAB_PAD, 0), textcoords="offset points", ha="left",
|
|
135
|
+
va="center", color=ln.get_color(), annotation_clip=False))
|
|
136
|
+
if ax.get_legend() is not None:
|
|
137
|
+
ax.get_legend().remove()
|
|
138
|
+
spread(labels) #TODO: review -> interval?
|
|
139
|
+
ax.add_artist(_Spread(labels))
|
|
140
|
+
return labels
|