Skip to content

Commit

Permalink
adding categorical colormaps to own namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
callumrollo committed Jan 30, 2021
1 parent 51b9db8 commit 59450e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ __pycache__
.idea
dist
cmcrameri.egg-info
venv
10 changes: 7 additions & 3 deletions cmcrameri/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
paths = list(Path(text_file_folder).glob('*.txt'))
crameri_cmaps = dict()
crameri_cmaps_r = dict()
crameri_cmaps_s = dict()
for cmap_path in paths:
# Name of colour map taken from text file
cmap_name = os.path.split(cmap_path)[1][:-4]
cm_data = np.loadtxt(cmap_path)
cm_data = np.loadtxt(str(cmap_path))
# Make a linear segmented colour map
if cmap_name[-1] == 'S':
crameri_cmaps_s[cmap_name] = LinearSegmentedColormap.from_list(cmap_name, cm_data)
continue
crameri_cmaps[cmap_name] = LinearSegmentedColormap.from_list(cmap_name, cm_data)
# reverse the colour map and add this to the dictionary crameri_cmaps_r
# reverse the colour map and add this to the dictionary crameri_cmaps_r, mpt fpr categorical maps
crameri_cmaps_r[cmap_name + '_r'] = LinearSegmentedColormap.from_list(cmap_name + '_r', cm_data[::-1, :])


Expand All @@ -43,9 +47,9 @@ def show_cmaps():
colourmap = crameri_cmaps[cmap_selected]
axs[c].pcolor(x, cmap=colourmap)
axs[c].text(5, -0.3, cmap_selected, fontsize=30)
# plt.savefig('colormaps')


# So colourmaps can be called in other programs
locals().update(crameri_cmaps)
locals().update(crameri_cmaps_r)
locals().update(crameri_cmaps_s)
Binary file modified cmcrameri/colormaps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 59450e7

Please sign in to comment.