bumplot 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.
- bumplot-0.1.0/.coverage +0 -0
- bumplot-0.1.0/.github/workflows/doc.yaml +41 -0
- bumplot-0.1.0/.github/workflows/lint.yaml +28 -0
- bumplot-0.1.0/.github/workflows/pypi.yaml +98 -0
- bumplot-0.1.0/.github/workflows/tests.yaml +30 -0
- bumplot-0.1.0/.github/workflows/type.yaml +25 -0
- bumplot-0.1.0/.gitignore +23 -0
- bumplot-0.1.0/.pre-commit-config.yaml +21 -0
- bumplot-0.1.0/LICENSE +21 -0
- bumplot-0.1.0/Makefile +17 -0
- bumplot-0.1.0/PKG-INFO +85 -0
- bumplot-0.1.0/README.md +64 -0
- bumplot-0.1.0/README_files/figure-commonmark/cell-2-output-1.png +0 -0
- bumplot-0.1.0/bumplot/__init__.py +4 -0
- bumplot-0.1.0/bumplot/_utils.py +28 -0
- bumplot-0.1.0/bumplot/bezier.py +42 -0
- bumplot-0.1.0/bumplot/main.py +104 -0
- bumplot-0.1.0/bumplot.egg-info/PKG-INFO +85 -0
- bumplot-0.1.0/bumplot.egg-info/SOURCES.txt +35 -0
- bumplot-0.1.0/bumplot.egg-info/dependency_links.txt +1 -0
- bumplot-0.1.0/bumplot.egg-info/requires.txt +2 -0
- bumplot-0.1.0/bumplot.egg-info/top_level.txt +1 -0
- bumplot-0.1.0/coverage-badge.svg +1 -0
- bumplot-0.1.0/docs/.gitignore +1 -0
- bumplot-0.1.0/docs/README.qmd +65 -0
- bumplot-0.1.0/docs/contributing.md +66 -0
- bumplot-0.1.0/docs/examples.md +151 -0
- bumplot-0.1.0/docs/index.md +55 -0
- bumplot-0.1.0/docs/reference/bezier.md +1 -0
- bumplot-0.1.0/docs/reference/bumplot.md +1 -0
- bumplot-0.1.0/docs/stylesheets/style.css +106 -0
- bumplot-0.1.0/mkdocs.yaml +60 -0
- bumplot-0.1.0/overrides/partials/footer.html +7 -0
- bumplot-0.1.0/pyproject.toml +61 -0
- bumplot-0.1.0/setup.cfg +4 -0
- bumplot-0.1.0/tests/__init__.py +0 -0
- bumplot-0.1.0/tests/test_main.py +74 -0
bumplot-0.1.0/.coverage
ADDED
|
Binary file
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
deploy:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- name: Configure Git Credentials
|
|
16
|
+
run: |
|
|
17
|
+
git config user.name github-actions[bot]
|
|
18
|
+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: 3.x
|
|
22
|
+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
|
23
|
+
- uses: actions/cache@v4
|
|
24
|
+
with:
|
|
25
|
+
key: mkdocs-material-${{ env.cache_id }}
|
|
26
|
+
path: .cache
|
|
27
|
+
restore-keys: |
|
|
28
|
+
mkdocs-material-
|
|
29
|
+
|
|
30
|
+
- name: Install uv
|
|
31
|
+
uses: astral-sh/setup-uv@v5
|
|
32
|
+
with:
|
|
33
|
+
enable-cache: true
|
|
34
|
+
|
|
35
|
+
- name: Install the project
|
|
36
|
+
run: uv sync --all-groups
|
|
37
|
+
|
|
38
|
+
- name: Deploy MkDocs
|
|
39
|
+
env:
|
|
40
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
41
|
+
run: PYTHONPATH=$(pwd) uv run mkdocs gh-deploy --force
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Check Code Formatting
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
check-formatting:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout repository
|
|
14
|
+
uses: actions/checkout@v3
|
|
15
|
+
|
|
16
|
+
- name: Set up Python
|
|
17
|
+
uses: actions/setup-python@v4
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.13"
|
|
20
|
+
|
|
21
|
+
- name: Install Ruff
|
|
22
|
+
run: pip install ruff==0.9.10
|
|
23
|
+
|
|
24
|
+
- name: Run Ruff format check
|
|
25
|
+
run: ruff format --check .
|
|
26
|
+
|
|
27
|
+
- name: Run Ruff linting and auto-fix
|
|
28
|
+
run: ruff check --fix .
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# This is taken from
|
|
2
|
+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#the-whole-ci-cd-workflow
|
|
3
|
+
# but with the following differences
|
|
4
|
+
# - removed the TestPyPI part
|
|
5
|
+
# - instead of `on: push`, we have `tags` in there too
|
|
6
|
+
|
|
7
|
+
name: Publish Python 🐍 distribution 📦 to PyPI
|
|
8
|
+
|
|
9
|
+
on:
|
|
10
|
+
push:
|
|
11
|
+
tags:
|
|
12
|
+
- "v[0-9]+.[0-9]+.[0-9]+*"
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build:
|
|
16
|
+
name: Build distribution 📦
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
with:
|
|
22
|
+
persist-credentials: false
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
uses: actions/setup-python@v5
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.x"
|
|
27
|
+
- name: Install pypa/build
|
|
28
|
+
run: python3 -m pip install build --user
|
|
29
|
+
- name: Build a binary wheel and a source tarball
|
|
30
|
+
run: python3 -m build
|
|
31
|
+
- name: Store the distribution packages
|
|
32
|
+
uses: actions/upload-artifact@v4
|
|
33
|
+
with:
|
|
34
|
+
name: python-package-distributions
|
|
35
|
+
path: dist/
|
|
36
|
+
|
|
37
|
+
publish-to-pypi:
|
|
38
|
+
name: >-
|
|
39
|
+
Publish Python 🐍 distribution 📦 to PyPI
|
|
40
|
+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
|
|
41
|
+
needs:
|
|
42
|
+
- build
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
environment:
|
|
45
|
+
name: pypi
|
|
46
|
+
url: https://pypi.org/p/pytest-cov
|
|
47
|
+
permissions:
|
|
48
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
49
|
+
|
|
50
|
+
steps:
|
|
51
|
+
- name: Download all the dists
|
|
52
|
+
uses: actions/download-artifact@v4
|
|
53
|
+
with:
|
|
54
|
+
name: python-package-distributions
|
|
55
|
+
path: dist/
|
|
56
|
+
- name: Publish distribution 📦 to PyPI
|
|
57
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
58
|
+
|
|
59
|
+
github-release:
|
|
60
|
+
name: >-
|
|
61
|
+
Sign the Python 🐍 distribution 📦 with Sigstore
|
|
62
|
+
and upload them to GitHub Release
|
|
63
|
+
needs:
|
|
64
|
+
- publish-to-pypi
|
|
65
|
+
runs-on: ubuntu-latest
|
|
66
|
+
permissions:
|
|
67
|
+
contents: write # IMPORTANT: mandatory for making GitHub Releases
|
|
68
|
+
id-token: write # IMPORTANT: mandatory for sigstore
|
|
69
|
+
steps:
|
|
70
|
+
- name: Download all the dists
|
|
71
|
+
uses: actions/download-artifact@v4
|
|
72
|
+
with:
|
|
73
|
+
name: python-package-distributions
|
|
74
|
+
path: dist/
|
|
75
|
+
- name: Sign the dists with Sigstore
|
|
76
|
+
uses: sigstore/gh-action-sigstore-python@v3.0.0
|
|
77
|
+
with:
|
|
78
|
+
inputs: >-
|
|
79
|
+
./dist/*.tar.gz
|
|
80
|
+
./dist/*.whl
|
|
81
|
+
- name: Create GitHub Release
|
|
82
|
+
env:
|
|
83
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
84
|
+
run: >-
|
|
85
|
+
gh release create
|
|
86
|
+
"$GITHUB_REF_NAME"
|
|
87
|
+
--repo "$GITHUB_REPOSITORY"
|
|
88
|
+
--notes ""
|
|
89
|
+
- name: Upload artifact signatures to GitHub Release
|
|
90
|
+
env:
|
|
91
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
92
|
+
# Upload to GitHub Release using the `gh` CLI.
|
|
93
|
+
# `dist/` contains the built packages, and the
|
|
94
|
+
# sigstore-produced signatures and certificates.
|
|
95
|
+
run: >-
|
|
96
|
+
gh release upload
|
|
97
|
+
"$GITHUB_REF_NAME" dist/**
|
|
98
|
+
--repo "$GITHUB_REPOSITORY"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Unit tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
python-version:
|
|
13
|
+
- "3.11"
|
|
14
|
+
- "3.12"
|
|
15
|
+
- "3.13"
|
|
16
|
+
env:
|
|
17
|
+
UV_PYTHON: ${{ matrix.python-version }}
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v5
|
|
23
|
+
with:
|
|
24
|
+
enable-cache: true
|
|
25
|
+
|
|
26
|
+
- name: Install the project
|
|
27
|
+
run: uv sync --all-groups
|
|
28
|
+
|
|
29
|
+
- name: Run tests
|
|
30
|
+
run: uv run pytest
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Check Static Typing
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
check-formatting:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout repository
|
|
14
|
+
uses: actions/checkout@v3
|
|
15
|
+
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v5
|
|
18
|
+
with:
|
|
19
|
+
enable-cache: true
|
|
20
|
+
|
|
21
|
+
- name: Install the project
|
|
22
|
+
run: uv sync --all-groups
|
|
23
|
+
|
|
24
|
+
- name: Run tests
|
|
25
|
+
run: uv run ty check
|
bumplot-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.11.7
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff
|
|
6
|
+
types_or: [python, pyi]
|
|
7
|
+
args: [--fix]
|
|
8
|
+
- id: ruff-format
|
|
9
|
+
types_or: [python, pyi]
|
|
10
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
11
|
+
rev: v5.0.0
|
|
12
|
+
hooks:
|
|
13
|
+
- id: check-yaml
|
|
14
|
+
- id: trailing-whitespace
|
|
15
|
+
- id: end-of-file-fixer
|
|
16
|
+
- id: check-added-large-files
|
|
17
|
+
- repo: https://github.com/python-jsonschema/check-jsonschema
|
|
18
|
+
rev: 0.28.2
|
|
19
|
+
hooks:
|
|
20
|
+
- id: check-github-workflows
|
|
21
|
+
args: ["--verbose"]
|
bumplot-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Year Name
|
|
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.
|
bumplot-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.PHONY: all
|
|
2
|
+
|
|
3
|
+
readme:
|
|
4
|
+
quarto render docs/README.qmd --output-dir ..
|
|
5
|
+
|
|
6
|
+
coverage:
|
|
7
|
+
uv run coverage run --source=bumplot -m pytest
|
|
8
|
+
uv run coverage report -m
|
|
9
|
+
uv run coverage xml
|
|
10
|
+
uv run genbadge coverage -i coverage.xml
|
|
11
|
+
rm coverage.xml
|
|
12
|
+
|
|
13
|
+
preview:
|
|
14
|
+
uv run mkdocs serve
|
|
15
|
+
|
|
16
|
+
test:
|
|
17
|
+
uv run pytest
|
bumplot-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bumplot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Easily create and customize bump charts in Python
|
|
5
|
+
Author-email: Joseph Barbier <joseph.barbierdarnal@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://y-sunflower.github.io/bumplot/
|
|
8
|
+
Project-URL: Issues, https://github.com/y-sunflower/bumplot/issues
|
|
9
|
+
Project-URL: Documentation, https://y-sunflower.github.io/bumplot/
|
|
10
|
+
Project-URL: Repository, https://github.com/y-sunflower/bumplot
|
|
11
|
+
Keywords: bump,bump plot,bump charts,matplotlib,data,visualization
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: matplotlib>=3.9.4
|
|
19
|
+
Requires-Dist: narwhals>=2.0.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<!-- Automatically generated, uses README.qmd to modify README.md -->
|
|
25
|
+
|
|
26
|
+
# `bumplot`: easily create and customize bump charts in Python
|
|
27
|
+
|
|
28
|
+
<img src="https://github.com/JosephBARBIERDARNAL/static/blob/main/python-libs/bumplot/image.png?raw=true" alt="bumplot logo" align="right" width="180px"/>
|
|
29
|
+
|
|
30
|
+
`bumplot` is a small Python package made to facilitate the creation of
|
|
31
|
+
**bump charts** using matplotlib and Bézier curves. It has high
|
|
32
|
+
customization capabilities too!
|
|
33
|
+
|
|
34
|
+
Bump charts are useful when the focus is on comparing **relative
|
|
35
|
+
rankings**—who is ahead of whom—rather than the exact magnitude of the
|
|
36
|
+
differences.
|
|
37
|
+
|
|
38
|
+
Check out the [online
|
|
39
|
+
documentation](https://y-sunflower.github.io/bumplot/)
|
|
40
|
+
|
|
41
|
+
<br> <br>
|
|
42
|
+
|
|
43
|
+
## Get started
|
|
44
|
+
|
|
45
|
+
``` python
|
|
46
|
+
import matplotlib.pyplot as plt
|
|
47
|
+
import pandas as pd
|
|
48
|
+
|
|
49
|
+
from bumplot import bumplot
|
|
50
|
+
|
|
51
|
+
data = pd.DataFrame(
|
|
52
|
+
{
|
|
53
|
+
"x": [2020, 2021, 2022, 2023],
|
|
54
|
+
"A": [10, 50, 20, 80],
|
|
55
|
+
"B": [40, 30, 60, 10],
|
|
56
|
+
"C": [90, 20, 70, 40],
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
x = "x"
|
|
60
|
+
y_columns = ["A", "B", "C"]
|
|
61
|
+
|
|
62
|
+
fig, ax = plt.subplots(figsize=(8, 4))
|
|
63
|
+
bumplot(
|
|
64
|
+
x=x,
|
|
65
|
+
y_columns=y_columns,
|
|
66
|
+
data=data,
|
|
67
|
+
curve_force=0.5,
|
|
68
|
+
plot_kwargs={"lw": 4},
|
|
69
|
+
scatter_kwargs={"s": 150, "ec": "black", "lw": 2},
|
|
70
|
+
colors=["#ffbe0b", "#ff006e", "#3a86ff"],
|
|
71
|
+
)
|
|
72
|
+
ax.legend()
|
|
73
|
+
ax.spines[["top", "right", "left", "bottom"]].set_visible(False)
|
|
74
|
+
ax.grid(alpha=0.4)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
[See more examples](https://y-sunflower.github.io/bumplot/examples/)
|
|
80
|
+
|
|
81
|
+
<br> <br>
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
pip install bumplot
|
bumplot-0.1.0/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<!-- Automatically generated, uses README.qmd to modify README.md -->
|
|
4
|
+
|
|
5
|
+
# `bumplot`: easily create and customize bump charts in Python
|
|
6
|
+
|
|
7
|
+
<img src="https://github.com/JosephBARBIERDARNAL/static/blob/main/python-libs/bumplot/image.png?raw=true" alt="bumplot logo" align="right" width="180px"/>
|
|
8
|
+
|
|
9
|
+
`bumplot` is a small Python package made to facilitate the creation of
|
|
10
|
+
**bump charts** using matplotlib and Bézier curves. It has high
|
|
11
|
+
customization capabilities too!
|
|
12
|
+
|
|
13
|
+
Bump charts are useful when the focus is on comparing **relative
|
|
14
|
+
rankings**—who is ahead of whom—rather than the exact magnitude of the
|
|
15
|
+
differences.
|
|
16
|
+
|
|
17
|
+
Check out the [online
|
|
18
|
+
documentation](https://y-sunflower.github.io/bumplot/)
|
|
19
|
+
|
|
20
|
+
<br> <br>
|
|
21
|
+
|
|
22
|
+
## Get started
|
|
23
|
+
|
|
24
|
+
``` python
|
|
25
|
+
import matplotlib.pyplot as plt
|
|
26
|
+
import pandas as pd
|
|
27
|
+
|
|
28
|
+
from bumplot import bumplot
|
|
29
|
+
|
|
30
|
+
data = pd.DataFrame(
|
|
31
|
+
{
|
|
32
|
+
"x": [2020, 2021, 2022, 2023],
|
|
33
|
+
"A": [10, 50, 20, 80],
|
|
34
|
+
"B": [40, 30, 60, 10],
|
|
35
|
+
"C": [90, 20, 70, 40],
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
x = "x"
|
|
39
|
+
y_columns = ["A", "B", "C"]
|
|
40
|
+
|
|
41
|
+
fig, ax = plt.subplots(figsize=(8, 4))
|
|
42
|
+
bumplot(
|
|
43
|
+
x=x,
|
|
44
|
+
y_columns=y_columns,
|
|
45
|
+
data=data,
|
|
46
|
+
curve_force=0.5,
|
|
47
|
+
plot_kwargs={"lw": 4},
|
|
48
|
+
scatter_kwargs={"s": 150, "ec": "black", "lw": 2},
|
|
49
|
+
colors=["#ffbe0b", "#ff006e", "#3a86ff"],
|
|
50
|
+
)
|
|
51
|
+
ax.legend()
|
|
52
|
+
ax.spines[["top", "right", "left", "bottom"]].set_visible(False)
|
|
53
|
+
ax.grid(alpha=0.4)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+

|
|
57
|
+
|
|
58
|
+
[See more examples](https://y-sunflower.github.io/bumplot/examples/)
|
|
59
|
+
|
|
60
|
+
<br> <br>
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
pip install bumplot
|
|
Binary file
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
|
|
3
|
+
import narwhals as nw
|
|
4
|
+
from narwhals.typing import IntoDataFrame
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _get_first_n_colors(n=int) -> list[str]:
|
|
8
|
+
"""
|
|
9
|
+
Get the first n colors from matplotlib rcParams.
|
|
10
|
+
"""
|
|
11
|
+
colors: list[str] = plt.rcParams["axes.prop_cycle"].by_key()["color"][:n]
|
|
12
|
+
return colors
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _ranked_df(df: IntoDataFrame, x: str, y_columns: list[str]):
|
|
16
|
+
"""
|
|
17
|
+
Convert a dataframe to a ranked version of it.
|
|
18
|
+
"""
|
|
19
|
+
df_native = nw.from_native(df).select(nw.col(x), nw.col(y_columns))
|
|
20
|
+
|
|
21
|
+
df_native_ranked = (
|
|
22
|
+
df_native.unpivot(on=y_columns, index=x)
|
|
23
|
+
.with_columns(nw.col("value").rank("ordinal").over(x))
|
|
24
|
+
.pivot(on="variable", index=x, values="value")
|
|
25
|
+
.select(nw.col(x), nw.col(y_columns))
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
return df_native_ranked
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from matplotlib.path import Path
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def bezier_curve(
|
|
6
|
+
x: np.ndarray,
|
|
7
|
+
y: np.ndarray,
|
|
8
|
+
force: float,
|
|
9
|
+
) -> tuple[list[tuple[float, float]], list[int]]:
|
|
10
|
+
"""
|
|
11
|
+
Generate vertices and path codes for a smooth cubic Bézier curve
|
|
12
|
+
passing through a sequence of points.
|
|
13
|
+
|
|
14
|
+
This function is used under the hood by [`bumplot()`](./bumplot.md),
|
|
15
|
+
but you can use it too.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
x: X-coordinates of the points.
|
|
19
|
+
y: Y-coordinates of the points.
|
|
20
|
+
force: Smoothing factor controlling curve tightness. Higher values
|
|
21
|
+
increase curvature by moving control points further away
|
|
22
|
+
from the anchors.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
vertices: List of (x, y) vertices including control points for the Bézier segments.
|
|
26
|
+
codes: Corresponding matplotlib Path codes for constructing the curve.
|
|
27
|
+
"""
|
|
28
|
+
vertices: list = []
|
|
29
|
+
codes: list = []
|
|
30
|
+
|
|
31
|
+
vertices.append((x[0], y[0]))
|
|
32
|
+
codes.append(Path.MOVETO)
|
|
33
|
+
|
|
34
|
+
for i in range(1, len(x)):
|
|
35
|
+
x0, y0 = x[i - 1], y[i - 1]
|
|
36
|
+
x1, y1 = x[i], y[i]
|
|
37
|
+
dx = (x1 - x0) * force
|
|
38
|
+
|
|
39
|
+
vertices.extend([(x0 + dx, y0), (x1 - dx, y1), (x1, y1)])
|
|
40
|
+
codes.extend([Path.CURVE4, Path.CURVE4, Path.CURVE4])
|
|
41
|
+
|
|
42
|
+
return vertices, codes
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
from matplotlib.axes import Axes
|
|
3
|
+
from matplotlib.path import Path
|
|
4
|
+
import matplotlib.patches as patches
|
|
5
|
+
from matplotlib.patches import PathPatch
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
from narwhals.typing import IntoDataFrame
|
|
10
|
+
|
|
11
|
+
from bumplot.bezier import bezier_curve
|
|
12
|
+
from bumplot._utils import _get_first_n_colors, _ranked_df
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def bumplot(
|
|
16
|
+
x: str,
|
|
17
|
+
y_columns: list[str],
|
|
18
|
+
data: IntoDataFrame,
|
|
19
|
+
curve_force: float = 1,
|
|
20
|
+
invert_y_axis: bool = True,
|
|
21
|
+
colors: list | None = None,
|
|
22
|
+
plot_kwargs: dict | None = None,
|
|
23
|
+
scatter_kwargs: dict | None = None,
|
|
24
|
+
ax: Axes | None = None,
|
|
25
|
+
) -> Axes:
|
|
26
|
+
"""
|
|
27
|
+
Creates bump plot, or bump chart, from multiple numerical
|
|
28
|
+
columns.
|
|
29
|
+
|
|
30
|
+
It requires the data to be in wide format (e.g., one column
|
|
31
|
+
per line you want to plot).
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
x: colname of the x-axis variable
|
|
35
|
+
y_columns: colnames of the y-axis variables
|
|
36
|
+
data: A dataframe
|
|
37
|
+
curve_force: Smoothing factor controlling curve tightness. Higher
|
|
38
|
+
values increase curvature by moving control points further away
|
|
39
|
+
from the anchors.
|
|
40
|
+
invert_y_axis: Whether to invert y axis
|
|
41
|
+
colors: An optional list of colors
|
|
42
|
+
plot_kwargs: Additional arguments passed to `patches.PathPatch()`
|
|
43
|
+
scatter_kwargs: Additional arguments passed to `scatter()`
|
|
44
|
+
ax: The matplotlib Axes used. Default to `plt.gca()`
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
The matplotlib Axes with the bump plot
|
|
48
|
+
"""
|
|
49
|
+
if ax is None:
|
|
50
|
+
ax: Axes = plt.gca()
|
|
51
|
+
|
|
52
|
+
default_plot_kwargs = {"facecolor": "none", "lw": 2}
|
|
53
|
+
if plot_kwargs is None:
|
|
54
|
+
plot_kwargs: dict = {}
|
|
55
|
+
default_plot_kwargs.update(plot_kwargs)
|
|
56
|
+
|
|
57
|
+
if scatter_kwargs is None:
|
|
58
|
+
scatter_kwargs: dict = {}
|
|
59
|
+
|
|
60
|
+
if colors is None:
|
|
61
|
+
colors: list[str] = _get_first_n_colors(n=len(y_columns))
|
|
62
|
+
else:
|
|
63
|
+
assert len(y_columns) <= len(colors), (
|
|
64
|
+
f"Not enough colors, expected <={len(y_columns)}, found {len(colors)}"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
ranked: IntoDataFrame = _ranked_df(data, x=x, y_columns=y_columns)
|
|
68
|
+
x_values_raw: np.ndarray = np.ravel(ranked.select(x).to_numpy())
|
|
69
|
+
|
|
70
|
+
if np.issubdtype(x_values_raw.dtype, np.number):
|
|
71
|
+
x_values = x_values_raw
|
|
72
|
+
x_labels = x_values_raw
|
|
73
|
+
else:
|
|
74
|
+
uniques = list(dict.fromkeys(x_values_raw)) # preserves order
|
|
75
|
+
mapping = {val: i for i, val in enumerate(uniques)}
|
|
76
|
+
x_values = np.array([mapping[val] for val in x_values_raw], dtype=int)
|
|
77
|
+
x_labels = x_values_raw
|
|
78
|
+
|
|
79
|
+
for i, col in enumerate(y_columns):
|
|
80
|
+
y_values: np.ndarray = np.ravel(ranked.select(col).to_numpy())
|
|
81
|
+
vertices, codes = bezier_curve(
|
|
82
|
+
x=x_values,
|
|
83
|
+
y=y_values,
|
|
84
|
+
force=curve_force,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
path: Path = Path(vertices=vertices, codes=codes)
|
|
88
|
+
patch: PathPatch = patches.PathPatch(
|
|
89
|
+
path=path,
|
|
90
|
+
edgecolor=colors[i],
|
|
91
|
+
**default_plot_kwargs,
|
|
92
|
+
)
|
|
93
|
+
ax.add_patch(patch)
|
|
94
|
+
ax.scatter(x_values, y_values, color=colors[i], label=col, **scatter_kwargs)
|
|
95
|
+
|
|
96
|
+
ticks: list[int] = list(range(1, len(y_columns) + 1))
|
|
97
|
+
if invert_y_axis:
|
|
98
|
+
ax.invert_yaxis()
|
|
99
|
+
else:
|
|
100
|
+
ticks: list[int] = list(reversed(ticks))
|
|
101
|
+
ax.set_yticks(ticks=ticks)
|
|
102
|
+
ax.set_xticks(ticks=np.unique(x_values), labels=np.unique(x_labels))
|
|
103
|
+
|
|
104
|
+
return ax
|