kx-plot 0.4.0__tar.gz → 0.6.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.4.0 → kx_plot-0.6.0}/CHANGELOG.md +134 -1
- kx_plot-0.6.0/PKG-INFO +264 -0
- kx_plot-0.4.0/PKG-INFO → kx_plot-0.6.0/README.md +95 -33
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/__init__.py +36 -9
- kx_plot-0.6.0/kx/_cramers.py +47 -0
- kx_plot-0.6.0/kx/_data.py +21 -0
- kx_plot-0.6.0/kx/_embed.py +88 -0
- kx_plot-0.6.0/kx/_evaluate.py +80 -0
- kx_plot-0.6.0/kx/_image.py +244 -0
- kx_plot-0.6.0/kx/_metrics.py +176 -0
- kx_plot-0.6.0/kx/_plot.py +347 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/_spec.py +9 -4
- kx_plot-0.6.0/kx/_stats.py +188 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/_util.py +29 -0
- kx_plot-0.6.0/kx/data/binary.csv +1001 -0
- kx_plot-0.6.0/kx/data/curves.csv +11 -0
- kx_plot-0.6.0/kx/data/embedding.csv +601 -0
- kx_plot-0.6.0/kx/data/history.csv +61 -0
- kx_plot-0.6.0/kx/data/importance.csv +16 -0
- kx_plot-0.6.0/kx/data/multiclass.csv +601 -0
- kx_plot-0.6.0/kx/data/regression.csv +501 -0
- kx_plot-0.6.0/kx/data/shapes.npz +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/kinds/__init__.py +1 -1
- kx_plot-0.6.0/kx/kinds/basic.py +390 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/kinds/dist.py +59 -4
- kx_plot-0.6.0/kx/kinds/image.py +387 -0
- kx_plot-0.6.0/kx/kinds/ml.py +491 -0
- kx_plot-0.6.0/kx/kinds/table.py +518 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/pyproject.toml +21 -4
- kx_plot-0.6.0/tests/helpers.py +16 -0
- kx_plot-0.6.0/tests/test_api.py +213 -0
- kx_plot-0.6.0/tests/test_basic.py +345 -0
- kx_plot-0.6.0/tests/test_data.py +131 -0
- kx_plot-0.6.0/tests/test_dist.py +191 -0
- kx_plot-0.6.0/tests/test_flags.py +377 -0
- kx_plot-0.6.0/tests/test_image.py +499 -0
- kx_plot-0.6.0/tests/test_ml.py +699 -0
- kx_plot-0.6.0/tests/test_plot.py +320 -0
- kx_plot-0.6.0/tests/test_stats.py +117 -0
- kx_plot-0.6.0/tests/test_table.py +567 -0
- kx_plot-0.6.0/tests/test_theme.py +195 -0
- kx_plot-0.4.0/README.md +0 -133
- kx_plot-0.4.0/kx/_data.py +0 -16
- kx_plot-0.4.0/kx/_plot.py +0 -150
- kx_plot-0.4.0/kx/kinds/basic.py +0 -181
- kx_plot-0.4.0/kx/kinds/table.py +0 -130
- kx_plot-0.4.0/tests/test_kx.py +0 -1309
- {kx_plot-0.4.0 → kx_plot-0.6.0}/.gitignore +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/LICENSE +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/_files.py +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/_grid.py +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/_save.py +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/_theme.py +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/data/cloud.csv +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/data/daily.csv +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/data/dists.csv +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/data/monthly.csv +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/data/passengers.csv +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/data/waves.csv +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/LICENCES.md +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/balance.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/bam.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/batlow.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/cork.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/davos.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/deep.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/haline.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/hawaii.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/lipari.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/oslo.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/roma.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/romaO.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/thermal.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/cmaps/vik.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/dark.mplstyle +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/light.mplstyle +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/LICENCES.md +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/dark2.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/ibm.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/okabe.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/paired.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/petroff10.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/petroff6.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/petroff8.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/set1.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/set2.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/tab10.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/tab20.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/tableaucb.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/tolbright.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/tolhc.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/tollight.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/tolmc.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/palettes/tolvibrant.txt +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/paper.mplstyle +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/poster.mplstyle +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/science.mplstyle +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/talk.mplstyle +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/kx/styles/thesis.mplstyle +0 -0
- {kx_plot-0.4.0 → kx_plot-0.6.0}/tests/conftest.py +0 -0
|
@@ -6,6 +6,137 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.6.0] - 2026-11-04
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `kx.plot` can draw a plot made of several panels (such as `pair`), returned as a flat array of axes in the place
|
|
14
|
+
of `ax=`, or a polar plot (such as `radar`), swapping a given `ax` for polar axes in the same cell.
|
|
15
|
+
- Statistics for the significance, association and clustering plots, in numpy without scipy and checked against
|
|
16
|
+
it: Kruskal-Wallis and pairwise Mann-Whitney tests, Holm-adjusted p-values, Cramér's V and hierarchical linkage.
|
|
17
|
+
- **Datasets** `embedding` (a 2-D embedding in 5 clusters, with the 10 features behind it) and `shapes` (210 small
|
|
18
|
+
images in 7 classes, some with artifacts, with masks, a model's predictions and saliency maps).
|
|
19
|
+
- `kx.load` reads a `.npz` dataset as a dict of arrays: `kx.load('shapes')['images']`.
|
|
20
|
+
- Image input for the image plots: an array of images (channels last or first), or a list of arrays, PIL images
|
|
21
|
+
or file paths, scaled to 0..1 whatever the dtype.
|
|
22
|
+
- **Plot kinds** `pie` and `donut`: shares of a whole, counting the categories of x or summing y per category.
|
|
23
|
+
`ann` writes the percent in each slice, `sort` puts the largest first, and past `top=` (7) slices the rest fold
|
|
24
|
+
into `other`. `donut` shows the total in its hole.
|
|
25
|
+
- **Plot kind** `radar`: one polygon per row of a table, or per group mean with `by=`, each column scaled to 0..1
|
|
26
|
+
with its range under its name; `raw` keeps the values.
|
|
27
|
+
- **Plot kind** `parallel`: parallel coordinates, one line per row, each axis scaled with its real min and max at
|
|
28
|
+
the ends. `by=` colours the lines by group and `mean` adds each group's mean.
|
|
29
|
+
- **Plot kind** `pair`: a scatter matrix of the numeric columns, coloured by `by=`, with a KDE per group on the
|
|
30
|
+
diagonal and shared axes. `cols=` picks the columns (at most 8).
|
|
31
|
+
- **Plot kind** `cluster`: `heat` with similar rows and columns side by side and dendrograms showing how they
|
|
32
|
+
group; `cluster-corr` groups correlated features. `method=` picks the linkage.
|
|
33
|
+
- **Plot kind** `mosaic`: two or three categoricals as tiles sized by their counts, `kx.plot(df, 'port', 'sex',
|
|
34
|
+
'survived', spec='mosaic')`. `ann` writes the counts.
|
|
35
|
+
- **Plot kinds** `treemap` and `sunburst`: a hierarchy of up to three categoricals sized by count, as nested
|
|
36
|
+
rectangles or as rings, `kx.plot(df, 'pclass', 'sex', spec='treemap')`. `ann` labels the tiles with room.
|
|
37
|
+
- **Flag** `facet`: the plot once per value of `facet=`, `kx.plot(df, 'pclass', 'port', 'crosstab-facet',
|
|
38
|
+
facet='sex')`, with every category in each panel, shared axes and one colour scale.
|
|
39
|
+
- **Flag** `sig` (`box`, `violin`): the Kruskal-Wallis p over the groups and, up to 6 groups, stars over each pair
|
|
40
|
+
that differs (Mann-Whitney, Holm-corrected); with `ann` the p-values instead.
|
|
41
|
+
- **Plot kind** `imgrid`: sample images, `kx.plot(images, labels, 'imgrid')`, one row of `n=` random images per
|
|
42
|
+
class (`seed=` repeats them), or the images at `idx=`. Only the images shown are read.
|
|
43
|
+
- **Plot kind** `meanimg`: the mean image of each class, `kx.plot(images, labels, 'meanimg')`, sizes matched to
|
|
44
|
+
the most common one; `std` shows how much each pixel varies instead, on one colour scale.
|
|
45
|
+
- **Plot kind** `colorhist`: each class's average histogram per colour channel, one line per class
|
|
46
|
+
(`kx.plot(images, labels, 'colorhist')`); `hsv` for hue, saturation and value, `map` for heat maps.
|
|
47
|
+
- **Plot kind** `imhist`: images beside their channel histograms, one row each, `kx.plot(images, 'imhist',
|
|
48
|
+
idx=[0, 1])` or `n=` random ones; `hsv` for hue, saturation and value.
|
|
49
|
+
- **Plot kind** `segmask`: images with their segmentation masks, `kx.plot(images, masks, 'segmask')`: the image,
|
|
50
|
+
the mask and an outline over the image; predicted masks as z add a second outline and the IoU.
|
|
51
|
+
- **Plot kind** `saliency`: saliency maps (Grad-CAM or any, computed elsewhere) over their images,
|
|
52
|
+
`kx.plot(images, maps, 'saliency')`, each scaled to 0..1 and smoothed up to its image; z adds a caption.
|
|
53
|
+
- **Plot kind** `miscls`: the images a model got wrong, `kx.plot(images, y_true, y_pred, 'miscls')`, captioned
|
|
54
|
+
'true -> predicted'; with a 2-D score as z, the most confident mistakes first.
|
|
55
|
+
- **Plot kind** `embed`: a 2-D embedding coloured by label, `kx.plot(xy, labels, 'embed')`, with no ticks and
|
|
56
|
+
equal aspect; `ann` names each group where it sits.
|
|
57
|
+
- `kx.embed(df, by='label')`: PCA (or `method='tsne'`, `'umap'` with the new `embed` extra) of a table or images,
|
|
58
|
+
then the `embed` plot; the coordinates are `ax.embedding`.
|
|
59
|
+
- `kx.cramers(df)`: Cramér's V between every pair of categorical columns as a heat map, `cluster=True` to group
|
|
60
|
+
them, `plot=False` for the matrix.
|
|
61
|
+
- `heat` takes `fmt=` for its `ann` numbers.
|
|
62
|
+
- Table kinds that group (`radar`, `parallel`, `pair`) take `by=` as a column name, left out of the columns drawn.
|
|
63
|
+
|
|
64
|
+
## [0.5.0] - 2026-10-24
|
|
65
|
+
|
|
66
|
+
### Added
|
|
67
|
+
|
|
68
|
+
- `kx.roc_auc(y_true, score)` and `kx.pr_ap(y_true, score)`: the area under the ROC curve (by trapezoids) and
|
|
69
|
+
the average precision (the step sum `Σ (Rₙ − Rₙ₋₁) Pₙ`), in numpy with no scikit-learn needed, and tied scores
|
|
70
|
+
counted as one step as scikit-learn does. Labels are 0/1 or bool with `1`/`True` positive; with two other labels
|
|
71
|
+
the later one in sorted order is positive. More than two labels, a 2-D score or only one class raise.
|
|
72
|
+
- **Datasets** for the machine-learning kinds, for `kx.load`: `binary` (a 0/1 `y` scored by two models, `gbm`
|
|
73
|
+
ranking better and `logreg` better calibrated), `multiclass` (a 3-class `y`, one probability column per class
|
|
74
|
+
`cat`, `dog`, `bird` summing to 1, and `pred`), `regression` (`actual`, `predicted` and an `x` the error grows
|
|
75
|
+
with), `history` (`loss`, `val_loss`, `accuracy`, `val_accuracy` per `epoch`, overfitting after about 30 epochs),
|
|
76
|
+
`importance` (`feature`, `importance`, `std`) and `curves` (learning-curve scores per training `size`,
|
|
77
|
+
`train_1..5` and `val_1..5`). `scripts/make_ml.py` writes them with a fixed seed.
|
|
78
|
+
- **Flag** `diag` (`scatter`, `hexbin`): a dashed `y = x` line across the range `x` and `y` share, to compare
|
|
79
|
+
predicted with actual values or two measurements of the same thing.
|
|
80
|
+
- **Flag** `fit` (`scatter`): a least-squares line with its slope and R² in the legend, which it draws. With a
|
|
81
|
+
categorical `z`, one line per group in the group's colour. With a log axis it raises, because a straight fit
|
|
82
|
+
is a curve there; fit the logs instead.
|
|
83
|
+
- **Plot kind** `cm`: a confusion matrix, `kx.plot(y_true, y_pred, 'cm')`, with the true classes down the rows
|
|
84
|
+
and the predicted ones along the columns, as in scikit-learn. Every label of either array gets a row and a
|
|
85
|
+
column, so a class that is never predicted still shows. `norm` divides each row by its total (the recall of
|
|
86
|
+
each class) with a percent colorbar, `ann` writes each cell's value and `nocb` drops the colorbar. A 2-D
|
|
87
|
+
`y_pred` raises with a hint to pass `proba.argmax(axis=1)`.
|
|
88
|
+
- **Plot kind** `roc`: the ROC curve, `kx.plot(y_true, score, 'roc')`, with the AUC in the legend
|
|
89
|
+
(`gbm (AUC 0.80)`), which it draws without `leg`. A dotted diagonal marks a random model, and both axes run
|
|
90
|
+
from 0 to 1 at equal scale. `z` adds a second model's score. A 2-D score, one column per class, draws one
|
|
91
|
+
curve per class, one-vs-rest, named after the DataFrame's columns or else the sorted labels of `y_true`.
|
|
92
|
+
- **Plot kind** `pr`: the precision-recall curve, `kx.plot(y_true, score, 'pr')`, with the average precision in
|
|
93
|
+
the legend (`gbm (AP 0.80)`) and a dotted baseline at the positive rate, what a random model gets. The curve
|
|
94
|
+
is drawn in the steps that the average precision sums. `z` adds a second model on the same baseline; a 2-D
|
|
95
|
+
score draws one curve per class, each with its own baseline in its colour.
|
|
96
|
+
- **Plot kind** `calib`: a reliability diagram, `kx.plot(y_true, score, 'calib')`: the observed positive rate
|
|
97
|
+
against the mean score in `bins=` equal-width bins over 0..1 (10 by default), with markers sized by the rows
|
|
98
|
+
in each bin, the diagonal a calibrated model lies on, and the Brier score in the legend (`gbm (Brier 0.201)`).
|
|
99
|
+
Empty bins are left out. `z` adds a second model; scores outside 0..1 raise.
|
|
100
|
+
- **Plot kind** `proba`: the score distribution per true class, `kx.plot(y_true, score, 'proba')`: one
|
|
101
|
+
histogram per class on the same `bins=` equal-width bins over 0..1 (20 by default), so their overlap shows
|
|
102
|
+
where the model confuses them. `norm` draws densities, for imbalanced classes. A 2-D score shows each row's
|
|
103
|
+
score for its own true class.
|
|
104
|
+
- **Plot kind** `thresh`: precision, recall and F1 against the decision threshold,
|
|
105
|
+
`kx.plot(y_true, score, 'thresh')`, where a row is positive when its score is at or above the threshold.
|
|
106
|
+
- **Flag** `best` (`thresh`, `loss`, `elbow`): a dashed vertical line at the threshold with the highest F1, labelled in the legend
|
|
107
|
+
(`best F1 0.74 at 0.38`).
|
|
108
|
+
- **Plot kinds** `gain` and `lift`: `kx.plot(y_true, score, 'gain')` draws the share of positives found against
|
|
109
|
+
the share of rows taken, highest scores first, between a dotted diagonal (a random order) and a dashed corner
|
|
110
|
+
at the positive rate (a perfect one). `lift` divides the gain by the random order's, so how many times more
|
|
111
|
+
positives the top rows hold, with a dotted line at 1. `z` adds a second model to both.
|
|
112
|
+
- **Plot kind** `pva`: predicted against actual for a regression, `kx.plot(actual, predicted, 'pva')`, with the
|
|
113
|
+
dashed `y = x` line, equal scales, and R², RMSE and MAE in the corner. Above 5,000 points it draws hexagons
|
|
114
|
+
(`hexbin`) instead of dots, so big test sets stay readable.
|
|
115
|
+
- **Plot kind** `resid`: residuals (`actual - predicted`) against predicted, with a dashed line at 0. `z` colours
|
|
116
|
+
the points as in `scatter`, such as by a feature, and takes `nocb`, `sym` and `logc`.
|
|
117
|
+
- **Plot kind** `imp`: feature importance, `kx.plot(df, 'feature', 'importance', 'std', 'imp')`, as bars lying
|
|
118
|
+
down with the largest on top and `z` as error bars. `top=` keeps the largest (20 by default) and the y label
|
|
119
|
+
says how many were left out.
|
|
120
|
+
- **Plot kind** `loss`: training curves, `kx.plot(history, 'loss')`. The first metric is a solid line and its
|
|
121
|
+
`val_` pair a dashed one in the same colour, against an `epoch` column or the row number from 1. Other metrics
|
|
122
|
+
have other scales, so `kx.plot(h[['accuracy', 'val_accuracy']], 'loss')` draws them. `best` marks the best
|
|
123
|
+
validation epoch: the lowest, or the highest for metrics named with `acc`, `auc`, `f1`, `precision` or `recall`.
|
|
124
|
+
- Table kinds also take a dict of columns, or anything with a `.history` dict such as a Keras `History`, so
|
|
125
|
+
`kx.plot(model.fit(...), 'loss')` works without importing Keras.
|
|
126
|
+
- **Plot kinds** `lcurve` and `vcurve`: cross-validated scores, `kx.plot(sizes, train_scores, val_scores,
|
|
127
|
+
'lcurve')`, in the shapes scikit-learn's `learning_curve` and `validation_curve` return (one row per x, one
|
|
128
|
+
column per fold). The mean is a line and ± one standard deviation a band in its colour; 1-D scores draw a line
|
|
129
|
+
without a band. `vcurve` is the same with a hyperparameter on x, so `logx` is the usual flag.
|
|
130
|
+
- **Plot kind** `elbow`: choosing the number of clusters, `kx.plot(ks, inertia, 'elbow')`, with `z` (such as the
|
|
131
|
+
silhouette score) on a second y axis on the right. `best` marks the knee: the point farthest from the line
|
|
132
|
+
between the first and last points, with both axes scaled to 0..1.
|
|
133
|
+
- `kx.evaluate(y_true, *scores)`: a model report in one figure, with the panels picked from the data. A binary
|
|
134
|
+
`y` with 1-D scores gets `roc`, `pr`, `calib` and `proba` (2 x 2), with up to two models in each panel but
|
|
135
|
+
`proba`. A 2-D score gets `roc` per class, the `cm` of the most likely class and `proba` of the true class. A
|
|
136
|
+
numeric `y` with more than 10 values gets `pva`, `resid` and a `hist` of the residuals. `spec=` adds a theme and
|
|
137
|
+
flags to every panel, and other keywords go to `kx.grid`. It returns the flat array of axes, as `kx.grid` does;
|
|
138
|
+
the figure is `axs[0].figure`.
|
|
139
|
+
|
|
9
140
|
## [0.4.0] - 2026-10-18
|
|
10
141
|
|
|
11
142
|
### Added
|
|
@@ -194,7 +325,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
194
325
|
- `kx.use`, `kx.show`, `kx.source`, `kx.grammar`, `kx.load` and the demo CSVs
|
|
195
326
|
- a workflow that publishes the dataset to Kaggle
|
|
196
327
|
|
|
197
|
-
[Unreleased]: https://github.com/vhrabar/kx-plot/compare/v0.
|
|
328
|
+
[Unreleased]: https://github.com/vhrabar/kx-plot/compare/v0.6.0...HEAD
|
|
329
|
+
[0.6.0]: https://github.com/vhrabar/kx-plot/compare/v0.5.0...v0.6.0
|
|
330
|
+
[0.5.0]: https://github.com/vhrabar/kx-plot/compare/v0.4.0...v0.5.0
|
|
198
331
|
[0.4.0]: https://github.com/vhrabar/kx-plot/compare/v0.3.0...v0.4.0
|
|
199
332
|
[0.3.0]: https://github.com/vhrabar/kx-plot/compare/v0.2.0...v0.3.0
|
|
200
333
|
[0.2.0]: https://github.com/vhrabar/kx-plot/compare/v0.1.0...v0.2.0
|
kx_plot-0.6.0/PKG-INFO
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: kx-plot
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: One-line matplotlib plots, themes and model-evaluation charts for notebooks and scripts, Kaggle-friendly
|
|
5
|
+
Project-URL: Homepage, https://github.com/vhrabar/kx-plot
|
|
6
|
+
Project-URL: Issues, https://github.com/vhrabar/kx-plot/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/vhrabar/kx-plot/blob/main/CHANGELOG.md
|
|
8
|
+
Project-URL: Kaggle, https://www.kaggle.com/datasets/vhrabar/kx-plot
|
|
9
|
+
Project-URL: Example Notebook, https://www.kaggle.com/code/vhrabar/kx-one-line-matplotlib-plots-and-themes
|
|
10
|
+
Author-email: Vedran Hrabar <vedran.hrabar@outlook.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: kx/styles/cmaps/LICENCES.md
|
|
14
|
+
License-File: kx/styles/palettes/LICENCES.md
|
|
15
|
+
Keywords: confusion-matrix,data-science,jupyter,kaggle,machine-learning,matplotlib,model-evaluation,plotting,roc-curve,themes,visualization
|
|
16
|
+
Classifier: Development Status :: 4 - Beta
|
|
17
|
+
Classifier: Framework :: Jupyter
|
|
18
|
+
Classifier: Framework :: Matplotlib
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Classifier: Intended Audience :: Education
|
|
21
|
+
Classifier: Intended Audience :: Science/Research
|
|
22
|
+
Classifier: Operating System :: OS Independent
|
|
23
|
+
Classifier: Programming Language :: Python :: 3
|
|
24
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
30
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
31
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
32
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
33
|
+
Requires-Python: >=3.10
|
|
34
|
+
Requires-Dist: matplotlib>=3.7
|
|
35
|
+
Requires-Dist: numpy>=1.23
|
|
36
|
+
Requires-Dist: pandas>=1.5
|
|
37
|
+
Provides-Extra: embed
|
|
38
|
+
Requires-Dist: scikit-learn>=1.2; extra == 'embed'
|
|
39
|
+
Requires-Dist: umap-learn>=0.5; extra == 'embed'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# kx-plot
|
|
43
|
+
|
|
44
|
+
One-line matplotlib plots and themes for notebooks and scripts.
|
|
45
|
+
|
|
46
|
+
`kx` is a small, plain-Python package with `.mplstyle` themes, palettes and colourmaps. It needs nothing beyond
|
|
47
|
+
matplotlib, numpy and pandas and works offline, so it also runs in Kaggle competition notebooks.
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
## Install
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install kx-plot
|
|
55
|
+
|
|
56
|
+
# adds t-SNE and UMAP to kx.embed (PCA needs neither)
|
|
57
|
+
pip install 'kx-plot[embed]'
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import kx; kx.use('dark')
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Kaggle
|
|
65
|
+
|
|
66
|
+
Attach the dataset instead (**Add Input → Datasets → `vhrabar/kx-plot`**), then:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import sys; sys.path.append('/kaggle/input/datasets/vhrabar/kx-plot')
|
|
70
|
+
import kx; kx.use('dark')
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
kx.use('light', palette='okabe', cmap='cividis') # notebook default: theme, palette, colormap
|
|
77
|
+
kx.plot(x, y, z, 'scatter-grid-leg') # spec: kind-theme-flag-...
|
|
78
|
+
kx.plot(x, y, 'bar-paper') # a theme in the spec applies to this plot only
|
|
79
|
+
with kx.context('paper'): ... # or to every plot in the block
|
|
80
|
+
kx.save('fig.png') # to /kaggle/working on Kaggle, else the current folder
|
|
81
|
+
for ax, col in zip(kx.grid(3), df.columns): # a figure of 3 panels, a flat array of axes
|
|
82
|
+
kx.plot(df, col, spec='hist', ax=ax)
|
|
83
|
+
kx.plot(df, 'month', 'y2025', 'bar') # DataFrame columns by name
|
|
84
|
+
kx.plot(x, y, 'line', linewidth=3) # other keywords go to matplotlib
|
|
85
|
+
kx.plot(df, 'value', spec='kde', by='group') # one density curve per group
|
|
86
|
+
kx.plot(df.value, spec='box', by=df.group) # one box per group (also ridge, violin, qq)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
| Token | Values |
|
|
90
|
+
|-------|-----------------------------------------------------------------------------------------------|
|
|
91
|
+
| kind | `line` `step` `area` `band` `scatter` `bar` `barh` `hist` `kde` `ridge` `ecdf` `box` `violin` |
|
|
92
|
+
| | `strip` `qq` `count` `crosstab` `hexbin` `heat` `missing` `nullmap` `pie` `donut` `radar` |
|
|
93
|
+
| | `parallel` `pair` `cluster` `mosaic` `treemap` `sunburst` |
|
|
94
|
+
| | ML: `cm` `roc` `pr` `calib` `proba` `thresh` `gain` `lift` `pva` `resid` `imp` `loss` |
|
|
95
|
+
| | `lcurve` `vcurve` `elbow` `embed` |
|
|
96
|
+
| | Images: `imgrid` `meanimg` `colorhist` `imhist` `segmask` `saliency` `miscls` |
|
|
97
|
+
| theme | `dark` `light` `paper` `science` `talk` `poster` `thesis` |
|
|
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` `sort` `ann` `mean` `median` `nocb` |
|
|
100
|
+
| | `sym` `logc` `corr` `all` `diag` `fit` `best` `raw` `sig` |
|
|
101
|
+
|
|
102
|
+
`stack` works with `area`, `bar`, `barh` and `hist`. `norm` is a 100% stack for `area` and a
|
|
103
|
+
density (area 1) for `hist`. `cum` makes `hist` cumulative; `hist-norm-cum` is the CDF.
|
|
104
|
+
`hist` puts every series on the same bins, so the bars line up.
|
|
105
|
+
`diag` adds a dashed `y = x` line to `scatter` and `hexbin`; `fit` adds a least-squares line to `scatter`, with
|
|
106
|
+
its slope and R² in the legend (one line per group with a categorical `z`).
|
|
107
|
+
|
|
108
|
+
`sig` on `box` and `violin` writes the Kruskal-Wallis p and brackets the pairs that differ, with stars (`ann`: the
|
|
109
|
+
p-values), Holm-corrected.
|
|
110
|
+
|
|
111
|
+
`facet` draws a plot once per value of a column, `kx.plot(df, 'pclass', 'port', 'crosstab-facet', facet='sex')`,
|
|
112
|
+
with every category in every panel, shared axes, and one colour scale and colorbar for the colour kinds.
|
|
113
|
+
|
|
114
|
+
Unknown tokens raise an error instead of being guessed, with the closest valid tokens as a hint.
|
|
115
|
+
Everything is inspectable: `kx.grammar()`, `kx.grammar('area')`, `kx.parse('leg-scatter')`, `kx.show('dark')`,
|
|
116
|
+
`kx.source('scatter')`.
|
|
117
|
+
|
|
118
|
+
### Tables
|
|
119
|
+
|
|
120
|
+
`kx.load('passengers')` is a demo table with numbers, categories and NaNs to try these on.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
kx.missing(df) # share of NaNs per column, the most missing on top
|
|
124
|
+
kx.plot(df, 'nullmap-sort') # where the NaNs are: one pixel row per table row
|
|
125
|
+
kx.plot(df, 'heat-corr-ann') # correlations of the numeric columns, -1 to 1
|
|
126
|
+
kx.plot(df, 'heat') # any numeric DataFrame or 2-D array as coloured cells
|
|
127
|
+
kx.cramers(df, cluster=True) # Cramér's V of the categorical columns, 0 to 1
|
|
128
|
+
kx.plot(df, 'cluster-corr') # correlations, similar columns side by side, with trees
|
|
129
|
+
kx.plot(df, 'pclass', spec='count', by='survived') # rows per category, split by a second column
|
|
130
|
+
kx.plot(df, 'pclass', 'port', 'crosstab-norm-ann') # how often each pair of categories occurs
|
|
131
|
+
kx.plot(df, 'port', 'sex', 'survived', spec='mosaic-ann') # tiles sized by count, up to 3 categoricals
|
|
132
|
+
kx.plot(df, 'pclass', 'sex', spec='treemap-ann') # a hierarchy of categories; 'sunburst' as rings
|
|
133
|
+
kx.plot(df, 'age', 'fare', 'hexbin-logc') # points per hexagon; with a z, its mean per hexagon
|
|
134
|
+
kx.plot(df, 'port', 'donut-ann') # shares of a whole, the total in the hole
|
|
135
|
+
kx.plot(df[['age', 'fare', 'pclass', 'survived']], 'radar', by='survived') # each group's profile
|
|
136
|
+
kx.plot(df[['age', 'fare', 'pclass', 'sex']], 'parallel-mean', by='sex') # every row across columns
|
|
137
|
+
kx.plot(df, 'pair', by='sex') # every numeric column against every other
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`heat`, `cluster`, `missing`, `nullmap`, `radar`, `parallel` and `pair` take the whole table and no column names
|
|
141
|
+
(`radar`, `parallel` and `pair` take `by=`, a column of groups); `kx.plot(df[cols], 'heat')` for some columns.
|
|
142
|
+
`wrap` breaks long tick labels onto several lines.
|
|
143
|
+
|
|
144
|
+

|
|
145
|
+
|
|
146
|
+
### Images
|
|
147
|
+
|
|
148
|
+
Image kinds take an `(N, H, W)` or `(N, H, W, C)` array (channels first works too), or a list of arrays, PIL images
|
|
149
|
+
or file paths, with the labels as `y`. `kx.load('shapes')` is a small demo set.
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
d = kx.load('shapes')
|
|
153
|
+
kx.plot(d['images'], d['labels'], 'imgrid') # 6 random images per class, one row each
|
|
154
|
+
kx.plot(paths, labels, 'imgrid', idx=[3, 17, 42]) # chosen images, titled with their labels
|
|
155
|
+
kx.plot(d['images'], d['labels'], 'meanimg') # the mean image of each class; -std: where pixels vary
|
|
156
|
+
kx.plot(d['images'], d['labels'], 'colorhist') # pixel values per channel and class; -hsv, -map
|
|
157
|
+
kx.plot(d['images'], 'imhist', idx=[0, 1]) # images beside their own channel histograms
|
|
158
|
+
kx.plot(d['images'], d['masks'], pred, 'segmask') # image, mask, outlines; a prediction adds its IoU
|
|
159
|
+
kx.plot(d['images'], d['saliency'], 'saliency') # Grad-CAM or any map over its image, smoothed to fit
|
|
160
|
+
kx.plot(d['images'], d['labels'], d['proba'], 'miscls') # the mistakes, the most confident first
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+

|
|
164
|
+
|
|
165
|
+
### Embeddings
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
kx.embed(df, by='label') # PCA of the numeric columns, explained variance on the axes
|
|
169
|
+
kx.embed(images, by=labels, method='tsne') # t-SNE or UMAP: pip install 'kx-plot[embed]'
|
|
170
|
+
kx.plot(xy, labels, 'embed-ann') # coordinates you already have, names at each group
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`kx.embed` returns the axes, and the coordinates are `ax.embedding`.
|
|
174
|
+
|
|
175
|
+
### Machine learning
|
|
176
|
+
|
|
177
|
+
`kx.load('binary')`, `'multiclass'`, `'regression'`, `'history'`, `'importance'` and `'curves'` are demo data for
|
|
178
|
+
these kinds. Metrics are computed in numpy: no scikit-learn needed.
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
kx.plot(y_true, score, 'roc') # ROC curve, AUC in the legend
|
|
182
|
+
kx.plot(y_true, gbm, logreg, 'pr') # a second model goes in z; AP and a random baseline
|
|
183
|
+
kx.plot(y_true, proba_df, 'roc') # a 2-D score: one curve per class, one-vs-rest
|
|
184
|
+
kx.plot(y_true, score, 'calib') # reliability diagram, Brier score in the legend
|
|
185
|
+
kx.plot(y_true, score, 'proba') # score histogram per true class
|
|
186
|
+
kx.plot(y_true, score, 'thresh-best') # precision, recall and F1 against the threshold
|
|
187
|
+
kx.plot(y_true, score, 'gain') # also 'lift'
|
|
188
|
+
kx.plot(y_true, y_pred, 'cm-norm-ann') # confusion matrix, each row the recall of a class
|
|
189
|
+
kx.plot(actual, predicted, 'pva') # predicted vs actual, R², RMSE and MAE
|
|
190
|
+
kx.plot(actual, predicted, feature, 'resid') # residuals, coloured by a feature
|
|
191
|
+
kx.plot(df, 'feature', 'importance', 'std', 'imp') # feature importance with error bars, top= 20
|
|
192
|
+
kx.plot(model.fit(...), 'loss-best') # training curves from a Keras History, dict or DataFrame
|
|
193
|
+
kx.plot(sizes, train_scores, val_scores, 'lcurve') # scikit-learn's learning_curve output; also 'vcurve'
|
|
194
|
+
kx.plot(ks, inertia, silhouette, 'elbow-best') # choosing k, the knee marked
|
|
195
|
+
kx.roc_auc(y_true, score), kx.pr_ap(y_true, score) # the metrics as numbers
|
|
196
|
+
kx.evaluate(y_true, gbm, logreg) # a report: the panels picked from the data
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The truth comes first, then the predictions. Binary labels are 0/1 or bool, with `1`/`True` the positive class;
|
|
200
|
+
with two other labels the later one in sorted order is positive. For multiclass, pass a 2-D score with one column
|
|
201
|
+
per class: the class names are the DataFrame's columns, or else the sorted labels of `y_true`. `roc`, `pr`, `calib`,
|
|
202
|
+
`gain` and `lift` draw their legend without `leg`, because the metric in it is the point of the plot.
|
|
203
|
+
|
|
204
|
+
`kx.evaluate(y_true, *scores)` draws `roc`, `pr`, `calib` and `proba` for a binary task, `roc`, `cm` and
|
|
205
|
+
`proba` for a 2-D score, and `pva`, `resid` and a residual `hist` for a numeric `y` with many values. It returns
|
|
206
|
+
the flat array of axes, like `kx.grid`; `spec='dark-grid'` styles every panel.
|
|
207
|
+
|
|
208
|
+

|
|
209
|
+
|
|
210
|
+
rcParams can be overridden in `kx.use` with `__` for dots: `kx.use('dark', figure__figsize=(8, 4))`.
|
|
211
|
+
|
|
212
|
+
Every kind, option, flag and config, with its output, is in the
|
|
213
|
+
[Example Usage notebook](https://github.com/vhrabar/kx-plot/blob/main/Example%20Usage.ipynb).
|
|
214
|
+
|
|
215
|
+
## Palettes
|
|
216
|
+
|
|
217
|
+
Palettes for `kx.use(theme, palette=...)`, they swap only the colours; a theme's
|
|
218
|
+
other cycled properties (such as `paper`'s linestyles) stay.
|
|
219
|
+
|
|
220
|
+
| Name | Source |
|
|
221
|
+
|------------------------------------------|--------------------|
|
|
222
|
+
| `okabe` | Okabe & Ito (2008) |
|
|
223
|
+
| `tolbright` `tolvibrant` `tollight` | Paul Tol |
|
|
224
|
+
| `tolhc` `tolmc` | Paul Tol |
|
|
225
|
+
| `petroff6` `petroff8` `petroff10` | Petroff (2021) |
|
|
226
|
+
| `tab10` `tab20` `tableaucb` | Tableau |
|
|
227
|
+
| `set1` `set2` `dark2` `paired` | ColorBrewer |
|
|
228
|
+
| `ibm` | IBM Design Colors |
|
|
229
|
+
|
|
230
|
+
`kx.palette('okabe')` returns the hex codes. A list of colours works too: `palette=['#264653', '#e9c46a']`.
|
|
231
|
+
|
|
232
|
+
## Colourmaps
|
|
233
|
+
|
|
234
|
+
Colourmaps for `kx.use(theme, cmap=...)` colour continuous values, such as a numeric `z` in `scatter`.
|
|
235
|
+
Without `cmap`, the theme's own default applies.
|
|
236
|
+
Add `_r` to any name to reverse it, e.g. `cmap="thermal_r"`.
|
|
237
|
+
|
|
238
|
+
| Name | Type |
|
|
239
|
+
|------------------------------------------------|----------------------------------|
|
|
240
|
+
| `viridis` `magma` `plasma` `inferno` `cividis` | Sequential, perceptually uniform |
|
|
241
|
+
| `turbo` | Sequential, rainbow |
|
|
242
|
+
| `blues` `greys` | Sequential, ColorBrewer |
|
|
243
|
+
| `coolwarm` | Diverging |
|
|
244
|
+
| `rdbu` | Diverging, ColorBrewer |
|
|
245
|
+
| `berlin` `managua` `vanimo` | Diverging, dark centre |
|
|
246
|
+
| `twilight` | Cyclic, for angles and phases |
|
|
247
|
+
| `thermal` `haline` `deep` | Sequential, cmocean (vendored) |
|
|
248
|
+
| `balance` | Diverging, cmocean (vendored) |
|
|
249
|
+
| `batlow` `lipari` `hawaii` `oslo` `davos` | Sequential, Crameri (vendored) |
|
|
250
|
+
| `vik` `roma` `bam` `cork` | Diverging, Crameri (vendored) |
|
|
251
|
+
| `romaO` | Cyclic, Crameri (vendored) |
|
|
252
|
+
|
|
253
|
+
`kx.cmaps()` lists the ones that are available in the installed matplotlib as those implemented in matplotlib 3.10 or newer
|
|
254
|
+
are not vendored.
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
Released under the MIT License. See [`LICENSE`](https://github.com/vhrabar/kx-plot/blob/main/LICENSE).
|
|
260
|
+
|
|
261
|
+
Copyright © 2026 Vedran Hrabar
|
|
262
|
+
|
|
263
|
+
Vendored palettes and colourmaps keep their own licences; see [`kx/styles/palettes/LICENCES.md`](https://github.com/vhrabar/kx-plot/blob/main/kx/styles/palettes/LICENCES.md)
|
|
264
|
+
and [`kx/styles/cmaps/LICENCES.md`](https://github.com/vhrabar/kx-plot/blob/main/kx/styles/cmaps/LICENCES.md).
|
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: kx-plot
|
|
3
|
-
Version: 0.4.0
|
|
4
|
-
Summary: One-line matplotlib plots and themes for notebook and scripts, Kaggle-friendly
|
|
5
|
-
Project-URL: Homepage, https://github.com/vhrabar/kx-plot
|
|
6
|
-
Project-URL: Issues, https://github.com/vhrabar/kx-plot/issues
|
|
7
|
-
Project-URL: Changelog, https://github.com/vhrabar/kx-plot/blob/main/CHANGELOG.md
|
|
8
|
-
Project-URL: Kaggle, https://www.kaggle.com/datasets/vhrabar/kx-plot
|
|
9
|
-
Author-email: Vedran Hrabar <vedran.hrabar@outlook.com>
|
|
10
|
-
License-Expression: MIT
|
|
11
|
-
License-File: LICENSE
|
|
12
|
-
License-File: kx/styles/cmaps/LICENCES.md
|
|
13
|
-
License-File: kx/styles/palettes/LICENCES.md
|
|
14
|
-
Keywords: jupyter,kaggle,matplotlib,plotting,themes,visualization
|
|
15
|
-
Classifier: Development Status :: 3 - Alpha
|
|
16
|
-
Classifier: Framework :: Jupyter
|
|
17
|
-
Classifier: Framework :: Matplotlib
|
|
18
|
-
Classifier: Intended Audience :: Science/Research
|
|
19
|
-
Classifier: Operating System :: OS Independent
|
|
20
|
-
Classifier: Programming Language :: Python :: 3
|
|
21
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
|
-
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
23
|
-
Requires-Python: >=3.10
|
|
24
|
-
Requires-Dist: matplotlib>=3.7
|
|
25
|
-
Requires-Dist: numpy>=1.23
|
|
26
|
-
Requires-Dist: pandas>=1.5
|
|
27
|
-
Description-Content-Type: text/markdown
|
|
28
|
-
|
|
29
1
|
# kx-plot
|
|
30
2
|
|
|
31
3
|
One-line matplotlib plots and themes for notebooks and scripts.
|
|
@@ -39,6 +11,9 @@ matplotlib, numpy and pandas and works offline, so it also runs in Kaggle compet
|
|
|
39
11
|
|
|
40
12
|
```bash
|
|
41
13
|
pip install kx-plot
|
|
14
|
+
|
|
15
|
+
# adds t-SNE and UMAP to kx.embed (PCA needs neither)
|
|
16
|
+
pip install 'kx-plot[embed]'
|
|
42
17
|
```
|
|
43
18
|
|
|
44
19
|
```python
|
|
@@ -73,15 +48,27 @@ kx.plot(df.value, spec='box', by=df.group) # one box per group (also rid
|
|
|
73
48
|
| Token | Values |
|
|
74
49
|
|-------|-----------------------------------------------------------------------------------------------|
|
|
75
50
|
| kind | `line` `step` `area` `band` `scatter` `bar` `barh` `hist` `kde` `ridge` `ecdf` `box` `violin` |
|
|
76
|
-
| | `strip` `qq` `count` `crosstab` `hexbin` `heat` `missing` `nullmap`
|
|
51
|
+
| | `strip` `qq` `count` `crosstab` `hexbin` `heat` `missing` `nullmap` `pie` `donut` `radar` |
|
|
52
|
+
| | `parallel` `pair` `cluster` `mosaic` `treemap` `sunburst` |
|
|
53
|
+
| | ML: `cm` `roc` `pr` `calib` `proba` `thresh` `gain` `lift` `pva` `resid` `imp` `loss` |
|
|
54
|
+
| | `lcurve` `vcurve` `elbow` `embed` |
|
|
55
|
+
| | Images: `imgrid` `meanimg` `colorhist` `imhist` `segmask` `saliency` `miscls` |
|
|
77
56
|
| theme | `dark` `light` `paper` `science` `talk` `poster` `thesis` |
|
|
78
57
|
| flags | `grid` `leg` `legout` `tight` `rot` `wrap` `logx` `logy` `logxy` `symlogy` `zero` `eq` `pct` |
|
|
79
|
-
| | `si`; per kind: `stack` `norm` `cum` `date` `mk` `sort` `ann` `mean` `median` `nocb`
|
|
80
|
-
| | `logc` `corr` `all`
|
|
58
|
+
| | `si` `facet`; per kind: `stack` `norm` `cum` `date` `mk` `sort` `ann` `mean` `median` `nocb` |
|
|
59
|
+
| | `sym` `logc` `corr` `all` `diag` `fit` `best` `raw` `sig` |
|
|
81
60
|
|
|
82
61
|
`stack` works with `area`, `bar`, `barh` and `hist`. `norm` is a 100% stack for `area` and a
|
|
83
62
|
density (area 1) for `hist`. `cum` makes `hist` cumulative; `hist-norm-cum` is the CDF.
|
|
84
63
|
`hist` puts every series on the same bins, so the bars line up.
|
|
64
|
+
`diag` adds a dashed `y = x` line to `scatter` and `hexbin`; `fit` adds a least-squares line to `scatter`, with
|
|
65
|
+
its slope and R² in the legend (one line per group with a categorical `z`).
|
|
66
|
+
|
|
67
|
+
`sig` on `box` and `violin` writes the Kruskal-Wallis p and brackets the pairs that differ, with stars (`ann`: the
|
|
68
|
+
p-values), Holm-corrected.
|
|
69
|
+
|
|
70
|
+
`facet` draws a plot once per value of a column, `kx.plot(df, 'pclass', 'port', 'crosstab-facet', facet='sex')`,
|
|
71
|
+
with every category in every panel, shared axes, and one colour scale and colorbar for the colour kinds.
|
|
85
72
|
|
|
86
73
|
Unknown tokens raise an error instead of being guessed, with the closest valid tokens as a hint.
|
|
87
74
|
Everything is inspectable: `kx.grammar()`, `kx.grammar('area')`, `kx.parse('leg-scatter')`, `kx.show('dark')`,
|
|
@@ -96,13 +83,88 @@ kx.missing(df) # share of NaNs per column, t
|
|
|
96
83
|
kx.plot(df, 'nullmap-sort') # where the NaNs are: one pixel row per table row
|
|
97
84
|
kx.plot(df, 'heat-corr-ann') # correlations of the numeric columns, -1 to 1
|
|
98
85
|
kx.plot(df, 'heat') # any numeric DataFrame or 2-D array as coloured cells
|
|
86
|
+
kx.cramers(df, cluster=True) # Cramér's V of the categorical columns, 0 to 1
|
|
87
|
+
kx.plot(df, 'cluster-corr') # correlations, similar columns side by side, with trees
|
|
99
88
|
kx.plot(df, 'pclass', spec='count', by='survived') # rows per category, split by a second column
|
|
100
89
|
kx.plot(df, 'pclass', 'port', 'crosstab-norm-ann') # how often each pair of categories occurs
|
|
90
|
+
kx.plot(df, 'port', 'sex', 'survived', spec='mosaic-ann') # tiles sized by count, up to 3 categoricals
|
|
91
|
+
kx.plot(df, 'pclass', 'sex', spec='treemap-ann') # a hierarchy of categories; 'sunburst' as rings
|
|
101
92
|
kx.plot(df, 'age', 'fare', 'hexbin-logc') # points per hexagon; with a z, its mean per hexagon
|
|
93
|
+
kx.plot(df, 'port', 'donut-ann') # shares of a whole, the total in the hole
|
|
94
|
+
kx.plot(df[['age', 'fare', 'pclass', 'survived']], 'radar', by='survived') # each group's profile
|
|
95
|
+
kx.plot(df[['age', 'fare', 'pclass', 'sex']], 'parallel-mean', by='sex') # every row across columns
|
|
96
|
+
kx.plot(df, 'pair', by='sex') # every numeric column against every other
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`heat`, `cluster`, `missing`, `nullmap`, `radar`, `parallel` and `pair` take the whole table and no column names
|
|
100
|
+
(`radar`, `parallel` and `pair` take `by=`, a column of groups); `kx.plot(df[cols], 'heat')` for some columns.
|
|
101
|
+
`wrap` breaks long tick labels onto several lines.
|
|
102
|
+
|
|
103
|
+

|
|
104
|
+
|
|
105
|
+
### Images
|
|
106
|
+
|
|
107
|
+
Image kinds take an `(N, H, W)` or `(N, H, W, C)` array (channels first works too), or a list of arrays, PIL images
|
|
108
|
+
or file paths, with the labels as `y`. `kx.load('shapes')` is a small demo set.
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
d = kx.load('shapes')
|
|
112
|
+
kx.plot(d['images'], d['labels'], 'imgrid') # 6 random images per class, one row each
|
|
113
|
+
kx.plot(paths, labels, 'imgrid', idx=[3, 17, 42]) # chosen images, titled with their labels
|
|
114
|
+
kx.plot(d['images'], d['labels'], 'meanimg') # the mean image of each class; -std: where pixels vary
|
|
115
|
+
kx.plot(d['images'], d['labels'], 'colorhist') # pixel values per channel and class; -hsv, -map
|
|
116
|
+
kx.plot(d['images'], 'imhist', idx=[0, 1]) # images beside their own channel histograms
|
|
117
|
+
kx.plot(d['images'], d['masks'], pred, 'segmask') # image, mask, outlines; a prediction adds its IoU
|
|
118
|
+
kx.plot(d['images'], d['saliency'], 'saliency') # Grad-CAM or any map over its image, smoothed to fit
|
|
119
|
+
kx.plot(d['images'], d['labels'], d['proba'], 'miscls') # the mistakes, the most confident first
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+

|
|
123
|
+
|
|
124
|
+
### Embeddings
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
kx.embed(df, by='label') # PCA of the numeric columns, explained variance on the axes
|
|
128
|
+
kx.embed(images, by=labels, method='tsne') # t-SNE or UMAP: pip install 'kx-plot[embed]'
|
|
129
|
+
kx.plot(xy, labels, 'embed-ann') # coordinates you already have, names at each group
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`kx.embed` returns the axes, and the coordinates are `ax.embedding`.
|
|
133
|
+
|
|
134
|
+
### Machine learning
|
|
135
|
+
|
|
136
|
+
`kx.load('binary')`, `'multiclass'`, `'regression'`, `'history'`, `'importance'` and `'curves'` are demo data for
|
|
137
|
+
these kinds. Metrics are computed in numpy: no scikit-learn needed.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
kx.plot(y_true, score, 'roc') # ROC curve, AUC in the legend
|
|
141
|
+
kx.plot(y_true, gbm, logreg, 'pr') # a second model goes in z; AP and a random baseline
|
|
142
|
+
kx.plot(y_true, proba_df, 'roc') # a 2-D score: one curve per class, one-vs-rest
|
|
143
|
+
kx.plot(y_true, score, 'calib') # reliability diagram, Brier score in the legend
|
|
144
|
+
kx.plot(y_true, score, 'proba') # score histogram per true class
|
|
145
|
+
kx.plot(y_true, score, 'thresh-best') # precision, recall and F1 against the threshold
|
|
146
|
+
kx.plot(y_true, score, 'gain') # also 'lift'
|
|
147
|
+
kx.plot(y_true, y_pred, 'cm-norm-ann') # confusion matrix, each row the recall of a class
|
|
148
|
+
kx.plot(actual, predicted, 'pva') # predicted vs actual, R², RMSE and MAE
|
|
149
|
+
kx.plot(actual, predicted, feature, 'resid') # residuals, coloured by a feature
|
|
150
|
+
kx.plot(df, 'feature', 'importance', 'std', 'imp') # feature importance with error bars, top= 20
|
|
151
|
+
kx.plot(model.fit(...), 'loss-best') # training curves from a Keras History, dict or DataFrame
|
|
152
|
+
kx.plot(sizes, train_scores, val_scores, 'lcurve') # scikit-learn's learning_curve output; also 'vcurve'
|
|
153
|
+
kx.plot(ks, inertia, silhouette, 'elbow-best') # choosing k, the knee marked
|
|
154
|
+
kx.roc_auc(y_true, score), kx.pr_ap(y_true, score) # the metrics as numbers
|
|
155
|
+
kx.evaluate(y_true, gbm, logreg) # a report: the panels picked from the data
|
|
102
156
|
```
|
|
103
157
|
|
|
104
|
-
|
|
105
|
-
|
|
158
|
+
The truth comes first, then the predictions. Binary labels are 0/1 or bool, with `1`/`True` the positive class;
|
|
159
|
+
with two other labels the later one in sorted order is positive. For multiclass, pass a 2-D score with one column
|
|
160
|
+
per class: the class names are the DataFrame's columns, or else the sorted labels of `y_true`. `roc`, `pr`, `calib`,
|
|
161
|
+
`gain` and `lift` draw their legend without `leg`, because the metric in it is the point of the plot.
|
|
162
|
+
|
|
163
|
+
`kx.evaluate(y_true, *scores)` draws `roc`, `pr`, `calib` and `proba` for a binary task, `roc`, `cm` and
|
|
164
|
+
`proba` for a 2-D score, and `pva`, `resid` and a residual `hist` for a numeric `y` with many values. It returns
|
|
165
|
+
the flat array of axes, like `kx.grid`; `spec='dark-grid'` styles every panel.
|
|
166
|
+
|
|
167
|
+

|
|
106
168
|
|
|
107
169
|
rcParams can be overridden in `kx.use` with `__` for dots: `kx.use('dark', figure__figsize=(8, 4))`.
|
|
108
170
|
|