Skip to content

Commit 7c1133f

Browse files
committed
Add histogram/boxplot in figure
1 parent 2d3e581 commit 7c1133f

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/simdec/visualization.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import itertools
2+
from typing import Literal
23

34
import matplotlib as mpl
45
import matplotlib.pyplot as plt
@@ -65,6 +66,7 @@ def visualization(
6566
bins: pd.DataFrame,
6667
palette: list[list[float]],
6768
n_bins: str | int = "auto",
69+
kind: Literal["histogram", "boxplot"] = "histogram",
6870
ax=None,
6971
) -> plt.Axes:
7072
"""Histogram plot of scenarios.
@@ -77,6 +79,8 @@ def visualization(
7779
List of colours corresponding to scenarios.
7880
n_bins : str or int
7981
Number of bins or method from `np.histogram_bin_edges`.
82+
kind: {"histogram", "boxplot"}
83+
Histogram or Box Plot.
8084
ax : Axes, optional
8185
Matplotlib axis.
8286
@@ -89,17 +93,28 @@ def visualization(
8993
# needed to get the correct stacking order
9094
bins.columns = pd.RangeIndex(start=len(bins.columns), stop=0, step=-1)
9195

92-
ax = sns.histplot(
93-
bins,
94-
multiple="stack",
95-
stat="probability",
96-
palette=palette,
97-
common_bins=True,
98-
common_norm=True,
99-
bins=n_bins,
100-
legend=False,
101-
ax=ax,
102-
)
96+
if kind == "histogram":
97+
ax = sns.histplot(
98+
bins,
99+
multiple="stack",
100+
stat="probability",
101+
palette=palette,
102+
common_bins=True,
103+
common_norm=True,
104+
bins=n_bins,
105+
legend=False,
106+
ax=ax,
107+
)
108+
elif kind == "boxplot":
109+
ax = sns.boxplot(
110+
bins,
111+
palette=palette[::-1],
112+
orient="h",
113+
order=list(bins.columns)[::-1],
114+
ax=ax,
115+
)
116+
else:
117+
raise ValueError("'kind' can only be 'histogram' or 'boxplot'")
103118
return ax
104119

105120

0 commit comments

Comments
 (0)