Data: Tabular Time Series Specialty: Endocrinology Laboratory: Blood Tests EHR: Demographics Diagnoses Medications Omics: Genomics Multi-omics Transcriptomics Wearable: Activity Clinical Purpose: Treatment Response Assessment Task: Biomarker Discovery
[c23b31]: / src / move / visualization / style.py

Download this file

49 lines (37 with data), 1.3 kB

 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
__all__ = [
"DEFAULT_DIVERGING_PALETTE",
"DEFAULT_QUALITATIVE_PALETTE",
"DEFAULT_PLOT_STYLE",
"color_cycle",
"style_settings",
]
from typing import ContextManager, cast
import matplotlib
import matplotlib.style
from cycler import cycler
from matplotlib.cm import ColormapRegistry
from matplotlib.colors import ListedColormap
DEFAULT_DIVERGING_PALETTE = "RdYlBu"
DEFAULT_QUALITATIVE_PALETTE = "Dark2"
DEFAULT_PLOT_STYLE = "ggplot"
def color_cycle(colormap: str) -> ContextManager:
"""Returns a context manager for using a color cycle in plots.
Args:
colormap: Name of qualitative color map.
Returns:
Context manager
"""
registry: ColormapRegistry = matplotlib.colormaps
colormap_ = registry[colormap]
if isinstance(colormap_, ListedColormap):
prop_cycle = cycler(color=colormap_.colors)
return matplotlib.rc_context({"axes.prop_cycle": prop_cycle})
raise ValueError("Only colormaps that are list of colors supported.")
def style_settings(style: str) -> ContextManager:
"""Returns a context manager for setting a plot's style.
Args:
style: Style name.
Returns:
Context manager
"""
return cast(ContextManager, matplotlib.style.context(style))