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 / metrics.py

Download this file

59 lines (51 with data), 1.8 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
49
50
51
52
53
54
55
56
57
58
__all__ = ["plot_metrics_boxplot"]
from collections.abc import Sequence
import matplotlib
import matplotlib.figure
import matplotlib.pyplot as plt
from move.core.typing import FloatArray
from move.visualization.style import (
DEFAULT_PLOT_STYLE,
DEFAULT_QUALITATIVE_PALETTE,
color_cycle,
style_settings,
)
def plot_metrics_boxplot(
scores: Sequence[FloatArray],
labels: Sequence[str],
style: str = DEFAULT_PLOT_STYLE,
colormap: str = DEFAULT_QUALITATIVE_PALETTE,
) -> matplotlib.figure.Figure:
"""Plot a box plot, showing the distribution of metrics per dataset. Each
score corresponds (for example) to a sample.
Args:
scores: List of dataset metrics
labels: List of dataset names
style: Name of style to apply to the plot
colormap: Name of colormap to use for the boxes
Returns:
Figure
"""
with style_settings(style), color_cycle(colormap):
labelcolor = matplotlib.rcParams["axes.labelcolor"]
fig, ax = plt.subplots()
comps = ax.boxplot(
scores[::-1],
labels=labels[::-1],
patch_artist=True,
vert=False,
capprops=dict(color=labelcolor),
flierprops=dict(
marker="d",
markersize=5,
markerfacecolor=labelcolor,
markeredgecolor=labelcolor,
),
medianprops=dict(color=labelcolor),
whiskerprops=dict(color=labelcolor),
)
prop_cycle = matplotlib.rcParams["axes.prop_cycle"]
for box, prop in zip(comps["boxes"], prop_cycle()):
box.update(dict(facecolor=prop["color"], edgecolor=labelcolor))
ax.set(xlim=(-0.05, 1.05), xlabel="Score", ylabel="Dataset")
return fig