Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Connor Hainje
pidanalysis
Commits
236dc4f2
Commit
236dc4f2
authored
Dec 07, 2021
by
connor.hainje@pnnl.gov
Browse files
Fix typo in seaborn method, add functions for making colormaps
parent
329decb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
packages/pidplots/pidplots/colors.py
View file @
236dc4f2
...
...
@@ -5,9 +5,10 @@ Connor Hainje (connor.hainje@pnnl.gov)
Defines the colors to be used for the detectors and particles.
"""
from
matplotlib.colors
import
LinearSegmentedColormap
import
seaborn
as
sns
_det_cmap
=
sns
.
cubehelix_patte
rn
(
_det_cmap
=
sns
.
cubehelix_pa
le
tte
(
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
]
else
:
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
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment