-
Notifications
You must be signed in to change notification settings - Fork 3
/
colorschemes.py
145 lines (130 loc) · 6.04 KB
/
colorschemes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
'''
Created on 19 Aug 2020
@author: Christoph Minz
@license: BSD 3-Clause
'''
from __future__ import annotations
from typing import List, Dict, Any, Optional
# This is the list of supported color schemes.
# When adding a new entry, please specify a value for each color key that is
# used by `causetplotting`.
# It is recommended to define at least the color-keys as listed in the scheme
# 'matplotlib' with the color 'core' as main brand core color and 'gray'
# identical to 'grey'.
ColorSchemes: Dict[str, Dict[str, str]] = {
'matplotlib': {'core': 'tab:blue',
'black': 'black',
'gray': 'tab:gray',
'grey': 'tab:gray',
'white': 'snow',
'purple': 'tab:purple',
'blue': 'tab:blue',
'cyan': 'tab:cyan',
'green': 'tab:green',
'lime': 'limegreen',
'yellow': 'gold',
'orange': 'tab:orange',
'red': 'tab:red',
'pink': 'tab:pink'},
# ---------------------------------------------------------------
# University of York, UK. Brand style added on 19/08/2020
# https://www.york.ac.uk/staff/external-relations/brand/colours/
'UniYork': {'core': '#00627D',
'black': '#25303B',
'gray': '#E7E2D3',
'grey': '#E7E2D3',
'white': '#E3E5E5',
'purple': '#9067A9',
'darkblue': '#00627D',
'blue': '#0095D6',
'cyan': '#00ABAA',
'green': '#65B32E',
'lime': '#CDD500',
'yellow': '#FBB800',
'orange': '#F18625',
'red': '#E62A32',
'pink': '#E2388D'},
# ---------------------------------------------------------------
# Imperial College London, UK. Brand style added on 19/08/2020
# http://www.imperial.ac.uk/brand-style-guide/visual-identity/brand-colours/
'ImperialLondon': {'core': '#002147',
'black': '#002147',
'gray': '#EBEEEE',
'grey': '#EBEEEE',
'coolgrey': '#9D9D9D',
'white': '#D4EFFC',
'violet': '#960078',
'iris': '#751E66',
'purple': '#653098',
'plum': '#321E6D',
'navy': '#002147',
'darkblue': '#003E74',
'blue': '#006EAF',
'cyan': '#009CBC',
'green': '#02893B',
'kermitgreen': '#66A40A',
'lime': '#BBCEOO',
'yellow': '#FFDD00',
'tangerine': '#EC7300',
'orange': '#D24000',
'cherry': '#E40043',
'red': '#DD2501',
'brick': '#A51900',
'pink': '#C81E78',
'raspberry': '#9F004E'}
}
__global_color_scheme: Dict[str, str] = ColorSchemes['matplotlib']
def pickColorScheme(schemeName: str) -> Dict[str, str]:
'''
Returns the scheme with name `schemeName`.
'''
try:
return ColorSchemes[schemeName]
except KeyError:
raise ValueError(
f'The color scheme \'{schemeName}\' is not defined.')
def setGlobalColorScheme(schemeName: str) -> None:
'''
Sets the scheme for all plots to `schemeName`.
'''
global __global_color_scheme
__global_color_scheme = pickColorScheme(schemeName)
def getGlobalColorScheme() -> Dict[str, str]:
'''
Gets the scheme for all plots.
'''
return __global_color_scheme
def getColor(color: str, schemeName: Optional[str] = None) -> str:
'''
Converts a color value string by the color scheme to a matplotlib color.
'''
CS: Dict[str, str] = getGlobalColorScheme() if schemeName is None else \
pickColorScheme(schemeName)
if color.startswith('cs:'):
color = CS[color[3:]]
return color
def convertColorsInDict(plotParams: Dict[str, Any],
schemeName: Optional[str] = None) -> Dict[str, Any]:
'''
Converts all color value strings in an dictionary.
'''
CS: Dict[str, str] = getGlobalColorScheme() if schemeName is None else \
pickColorScheme(schemeName)
for key, value in plotParams.items():
if isinstance(value, str) and value.startswith('cs:'):
value = CS[value[3:]]
plotParams[key] = value
return plotParams
def convertColorsInList(plotParams: List[str],
schemeName: Optional[str] = None) -> List[str]:
'''
Converts all color value strings in a list.
'''
CS: Dict[str, str] = getGlobalColorScheme() if schemeName is None else \
pickColorScheme(schemeName)
for i, value in enumerate(plotParams):
if value.startswith('cs:'):
value = CS[value[3:]]
plotParams[i] = value
return plotParams