Commit 236dc4f2 authored by's avatar
Browse files

Fix typo in seaborn method, add functions for making colormaps

parent 329decb1
......@@ -5,9 +5,10 @@ Connor Hainje (
Defines the colors to be used for the detectors and particles.
from matplotlib.colors import LinearSegmentedColormap
import seaborn as sns
_det_cmap = sns.cubehelix_pattern(
_det_cmap = sns.cubehelix_palette(
5, start=1.5, rot=1.5, dark=0.3, light=0.8, reverse=True
......@@ -28,3 +29,38 @@ PARTICLES = {
"p": f"C{4}",
"d": f"C{5}",
def fill_color_list(color_list, detectors=True):
from . import const
if color_list is not None:
return color_list
if detectors:
return [DETECTORS[d] for d in const.DETECTORS]
return [PARTICLES[h] for h in const.PARTICLES]
def make_colormap(color_list, detectors=True):
color_list = fill_color_list(color_list, detectors=detectors)
cmap_name = "detectors" if detectors else "particles"
cmap = LinearSegmentedColormap.from_list(cmap_name, color_list, N=len(color_list))
return cmap
def make_linear_colormap(color, cmap_name="custom_cmap", low=0.3, high=0.8):
from matplotlib.colors import to_rgba, rgb_to_hsv, hsv_to_rgb
hsv = rgb_to_hsv(to_rgba(color, alpha=1)[:3])
lo = hsv_to_rgb((hsv[0], hsv[1], low))
hi = hsv_to_rgb((hsv[0], hsv[1], high))
cdict = {
"red": ((0.0, lo[0], lo[0]), (1.0, hi[0], hi[0])),
"green": ((0.0, lo[1], lo[1]), (1.0, hi[1], hi[1])),
"blue": ((0.0, lo[2], lo[2]), (1.0, hi[2], hi[2])),
return LinearSegmentedColormap(cmap_name, cdict)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment