Skip to content

Commit

Permalink
Added cmap.roll
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain-Rama authored Nov 19, 2023
1 parent ff386d9 commit 502f86b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Chatoyant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
import matplotlib as mpl
import numpy as np
import colorsys
from bokeh.palettes import all_palettes as bokeh_palettes
Expand Down Expand Up @@ -111,9 +112,11 @@ def from_matplotlib(self, name="inferno", n=10):

try:
plt_map = plt.cm.get_cmap(name, n).colors * 255


# Many plt Colormaps do not have the .colors attribute. Don't ask why.
except (ValueError, AttributeError):

plt_map = plt.cm.get_cmap(name, n)
plt_map = plt_map(range(n)) * 255
# Removing alpha channel, converting to int
Expand Down Expand Up @@ -192,6 +195,12 @@ def loop(self, n=1):
name = self.name + f"-Looped_{n}"

return ColorMap(color_map=color_map, name=name)

def roll(self, n=1):
name = self.name + f"-rolled_{n}"
color_map = self.color_map
rolled = color_map[-n:] + color_map[:-n]
return ColorMap(color_map=rolled, name=name)

def extend(self, n=10):
# Method to extend the colormap by n.
Expand Down Expand Up @@ -282,6 +291,6 @@ def name(self):
return self.name

if __name__ == '__main__':
cmap = ColorMap().from_matplotlib('inferno', n=100)
cmap = ColorMap().from_matplotlib('viridis', n=10)

print(cmap)

0 comments on commit 502f86b

Please sign in to comment.