Skip to content

Commit 76c9bf1

Browse files
authored
Add a script to generate palettes from matplotlib colormaps (#31)
* Add a script to generate palettes from matplotlib colormaps * Add the default colormaps for matplotlib and yt viridis and arbre, respectively.
1 parent a9c20e6 commit 76c9bf1

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

cmyt.arbre.pal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
qqrrsstuuvvwwxxyyzz{{||}}~~���������������������������������������������������������������}|zywvtrqonljigedba_^\[YXWUTSRPONMLKJIHGFEDDCBAA@?>>=<<;::99876654432210//.--,++**))((((()))*+,-.013579;>@CEHKNQTWZ]adgknruy|������������������������������������� !""#$%%&&'(())*++,,--..///00112223334455566778899::;<<=>?@ABDEFHIKMNPRTVXZ\^`bdfhjlnprtuwy{|~����������������������������������������������������������������������������������������������������������������������������������������������"$'),.1368:=?BDGILNPSUXZ]_bdgilnqsvx{~������������������������������������������������������������������������������������������������������������������������������������������������������������������~|zxusqnligdb_]ZXURPMKHEC@>;97421/-,,++,-/148<@Edddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd

mpl_colormap_to_pal.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import importlib
5+
6+
import matplotlib as mpl
7+
import numpy as np
8+
9+
parser = argparse.ArgumentParser(
10+
description="Generate Amrvis palette files from matplotlib colormaps."
11+
)
12+
parser.add_argument("cmap", nargs="+", help="the name of a matplotlib colormap")
13+
parser.add_argument(
14+
"--import",
15+
action="append",
16+
dest="extra_imports",
17+
metavar="MODULE",
18+
default=[],
19+
help="module to import for additional colormaps",
20+
)
21+
args = parser.parse_args()
22+
print(args)
23+
24+
for name in args.extra_imports:
25+
importlib.import_module(name)
26+
27+
for cm_name in args.cmap:
28+
cmap = mpl.colormaps.get_cmap(cm_name)
29+
colors = cmap.resampled(256)(np.linspace(0, 1, 256))
30+
data = np.round(colors * (255, 255, 255, 100)).astype(np.uint8).T.reshape(-1)
31+
filename = f"{cmap.name}.pal"
32+
data.tofile(filename)
33+
print(f"wrote palette to {filename}")

viridis.pal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DDEEFFFFGGGGGHHHHHHHHHHHHHHHHHGGGGGFFFFEEEDDDCCBBBAA@@??>>>==<<;;::998877665544332211100//...--,,,++***)))(('''&&&%%%$$###"""!!!!  !!""#$%%&'()*,-./124578:;=?@BDFHJLNPRTVXZ\^`cegilnpsuwz|�������������������������������������������������
2+
 !#$%&()*,-./02345789:;=>?@ABDEFGHIJLMNOPQRSTUVXYZ[\]^_`abcdefghijklmnopqqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������������������������TVWYZ\]^`acdeghijlmnopqstuvwxyzz{|}~~���������������������������������������������������������������������������������������������������������������������������~}||{zyyxwvutsrqponmlkjihgedcb`_^\[ZXWVTSQPNMKIHFECA@><;976420/-+)(&%#!  !#%dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd

0 commit comments

Comments
 (0)