kbird 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.
- kbird-0.1.0/PKG-INFO +67 -0
- kbird-0.1.0/README.md +56 -0
- kbird-0.1.0/pyproject.toml +17 -0
- kbird-0.1.0/src/kbird/__init__.py +42 -0
kbird-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: kbird
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: kBird colourmap is way better than viridis
|
|
5
|
+
Author: Alex Marshall
|
|
6
|
+
Author-email: Alex Marshall <a.marshall@fathom.global>
|
|
7
|
+
Requires-Dist: matplotlib>=3.10.8
|
|
8
|
+
Requires-Dist: numpy>=2.4.3
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# kBird
|
|
13
|
+
|
|
14
|
+
`kBird` brings CERN's **kBird** colormap into `matplotlib`. It registers the colormap and sets it as your global default.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## How to use
|
|
19
|
+
|
|
20
|
+
### 1. Global default in matplotlib
|
|
21
|
+
|
|
22
|
+
To use `kBird`, simply import the library and call `set()`.
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
|
|
26
|
+
import kbird
|
|
27
|
+
kbird.set()
|
|
28
|
+
|
|
29
|
+
# All plots will use kBird instead of viridis
|
|
30
|
+
plt.imshow(Z)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Using kBird inside a specific block
|
|
34
|
+
|
|
35
|
+
If you do not want to change your global `matplotlib` defaults and only want to use `kBird` for a single plot, you can use the `style()` context manager:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import kbird
|
|
39
|
+
import matplotlib.pyplot as plt
|
|
40
|
+
|
|
41
|
+
# Only plots generated inside this block will use kBird
|
|
42
|
+
with kbird.style():
|
|
43
|
+
plt.imshow(Z)
|
|
44
|
+
plt.show()
|
|
45
|
+
|
|
46
|
+
# Any plot out here will fall back to your standard matplotlib default
|
|
47
|
+
plt.imshow(Z)
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3. Manual Colormap Access
|
|
52
|
+
|
|
53
|
+
If you prefer to pass the colormap explicitly to `matplotlib` functions, you can import the colormap object directly:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import matplotlib.pyplot as plt
|
|
57
|
+
from kbird import kbird_cmap
|
|
58
|
+
|
|
59
|
+
plt.imshow(Z, cmap=kbird_cmap)
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
This project is licensed under the MIT License.
|
kbird-0.1.0/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# kBird
|
|
2
|
+
|
|
3
|
+
`kBird` brings CERN's **kBird** colormap into `matplotlib`. It registers the colormap and sets it as your global default.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## How to use
|
|
8
|
+
|
|
9
|
+
### 1. Global default in matplotlib
|
|
10
|
+
|
|
11
|
+
To use `kBird`, simply import the library and call `set()`.
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
|
|
15
|
+
import kbird
|
|
16
|
+
kbird.set()
|
|
17
|
+
|
|
18
|
+
# All plots will use kBird instead of viridis
|
|
19
|
+
plt.imshow(Z)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Using kBird inside a specific block
|
|
23
|
+
|
|
24
|
+
If you do not want to change your global `matplotlib` defaults and only want to use `kBird` for a single plot, you can use the `style()` context manager:
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import kbird
|
|
28
|
+
import matplotlib.pyplot as plt
|
|
29
|
+
|
|
30
|
+
# Only plots generated inside this block will use kBird
|
|
31
|
+
with kbird.style():
|
|
32
|
+
plt.imshow(Z)
|
|
33
|
+
plt.show()
|
|
34
|
+
|
|
35
|
+
# Any plot out here will fall back to your standard matplotlib default
|
|
36
|
+
plt.imshow(Z)
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 3. Manual Colormap Access
|
|
41
|
+
|
|
42
|
+
If you prefer to pass the colormap explicitly to `matplotlib` functions, you can import the colormap object directly:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import matplotlib.pyplot as plt
|
|
46
|
+
from kbird import kbird_cmap
|
|
47
|
+
|
|
48
|
+
plt.imshow(Z, cmap=kbird_cmap)
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "kbird"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "kBird colourmap is way better than viridis"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Alex Marshall", email = "a.marshall@fathom.global" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"matplotlib>=3.10.8",
|
|
12
|
+
"numpy>=2.4.3",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[build-system]
|
|
16
|
+
requires = ["uv_build>=0.9.26,<0.10.0"]
|
|
17
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import matplotlib as mpl
|
|
2
|
+
from matplotlib.colors import LinearSegmentedColormap
|
|
3
|
+
from contextlib import contextmanager
|
|
4
|
+
|
|
5
|
+
_stops = [0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0]
|
|
6
|
+
_red = [0.2082, 0.0592, 0.0780, 0.0232, 0.1802, 0.5301, 0.8186, 0.9956, 0.9764]
|
|
7
|
+
_green = [0.1664, 0.3599, 0.5041, 0.6419, 0.7178, 0.7492, 0.7328, 0.7862, 0.9832]
|
|
8
|
+
_blue = [0.5293, 0.8684, 0.8385, 0.7914, 0.6425, 0.4662, 0.3499, 0.1968, 0.0539]
|
|
9
|
+
|
|
10
|
+
_cdict = {
|
|
11
|
+
'red': [[_stops[i], _red[i], _red[i]] for i in range(len(_stops))],
|
|
12
|
+
'green': [[_stops[i], _green[i], _green[i]] for i in range(len(_stops))],
|
|
13
|
+
'blue': [[_stops[i], _blue[i], _blue[i]] for i in range(len(_stops))]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
kbird_cmap = LinearSegmentedColormap('kBird', _cdict)
|
|
17
|
+
|
|
18
|
+
def set():
|
|
19
|
+
if 'kBird' not in mpl.colormaps:
|
|
20
|
+
mpl.colormaps.register(kbird_cmap, name='kBird')
|
|
21
|
+
mpl.colormaps.register(kbird_cmap, name='kbird')
|
|
22
|
+
|
|
23
|
+
mpl.rcParams['image.cmap'] = 'kBird'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@contextmanager
|
|
27
|
+
def style():
|
|
28
|
+
"""Context manager to temporarily apply kBird defaults."""
|
|
29
|
+
# Register if not already done
|
|
30
|
+
if 'kBird' not in mpl.colormaps:
|
|
31
|
+
mpl.colormaps.register(kbird_cmap, name='kBird')
|
|
32
|
+
|
|
33
|
+
old_cmap = mpl.rcParams['image.cmap']
|
|
34
|
+
mpl.rcParams['image.cmap'] = 'kBird'
|
|
35
|
+
try:
|
|
36
|
+
yield
|
|
37
|
+
finally:
|
|
38
|
+
# Restore original default afterward
|
|
39
|
+
mpl.rcParams['image.cmap'] = old_cmap
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
__all__ = ['kbird', 'set']
|