Skip to content

Commit 014cf31

Browse files
committed
Example repo.
0 parents  commit 014cf31

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.egg-info
2+
.*.swp
3+
*.o
4+
*.pyc
5+
*.pyd
6+
*.so
7+
.cache/
8+
.eggs/
9+
.ipynb_checkpoints/
10+
.pytest_cache/
11+
build/
12+
dist/
13+
htmlcov/
14+
oprofile_data/
15+
.coverage
16+
.gdb_history

LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) YEAR, AUTHOR
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Template package for distributing Matplotlib colormaps
2+
======================================================
3+
4+
This is a template package for distributing Matplotlib colormaps as Python
5+
packages.
6+
7+
To use it, clone this repository, edit the (intentionally commented-out)
8+
metadata in ``setup.py``, and edit the colormap data in ``lib/nifty.py`` and
9+
rename it to your own colormap name.
10+
11+
You can then install the package using ``pip install ...`` (or alternatively
12+
just move ``lib/nifty.py`` into your own Python project), then use the colormap
13+
with e.g.
14+
15+
.. code-block:: python
16+
17+
from matplotlib import pyplot as plt
18+
import nifty
19+
20+
fig, ax = plt.subplots()
21+
ax.imshow([[0, 1], [2, 3]], cmap=nifty.cmap)
22+
23+
# or register the colormap to use the name as string
24+
25+
nifty.register_cmap()
26+
fig, ax = plt.subplots()
27+
ax.imshow([[0, 1], [2, 3]], cmap="nifty")
28+
29+
and just visualize the colormap with
30+
31+
.. code-block:: sh
32+
33+
$ python -m nifty

lib/nifty.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from matplotlib import colors as mcolors, cm
2+
3+
4+
# The name of the colormap.
5+
_colormap_name = "nifty"
6+
# The colormap data, as a list of RGB tuples.
7+
_colormap_data = [
8+
(0.0, 0.0, 0.0),
9+
(0.0, 0.0, 0.5),
10+
(0.0, 0.5, 0.5),
11+
(0.5, 0.5, 0.5),
12+
(0.5, 0.5, 1.0),
13+
(1.0, 1.0, 1.0),
14+
]
15+
16+
17+
cmap = mcolors.ListedColormap(_colormap_data, _colormap_name)
18+
19+
20+
def register_cmap():
21+
cm.register_cmap(cmap=cmap)
22+
23+
24+
if __name__ == "__main__":
25+
26+
from matplotlib import pyplot as plt
27+
28+
fig = plt.figure()
29+
sm = cm.ScalarMappable(cmap=cmap)
30+
sm.set_array([])
31+
fig.colorbar(sm)
32+
plt.show()

setup.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from setuptools import find_packages, setup
2+
3+
4+
setup(
5+
name=#"nifty-cmap",
6+
version=#"0.1",
7+
description=#"A nifty description.",
8+
author=#"Me",
9+
author_email=#"my@email.address",
10+
url=#"https://my.url",
11+
license=#"MIT",
12+
py_modules=#["nifty"],
13+
package_dir={"": "lib"},
14+
install_requires=["matplotlib"],
15+
)

0 commit comments

Comments
 (0)