File tree Expand file tree Collapse file tree 1 file changed +26
-11
lines changed
Expand file tree Collapse file tree 1 file changed +26
-11
lines changed Original file line number Diff line number Diff line change 11import itertools
2+ from typing import Literal
23
34import matplotlib as mpl
45import 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
You can’t perform that action at this time.
0 commit comments