@@ -196,8 +196,8 @@ def hyperslicer2(arr, *args, ax=None, lognorm=False, colorbar=True, **kwargs):
196196 return controls
197197
198198
199- def ridgeplot (data , * , overlap = 0.5 , xlabel = None , ylabel = "Per-line values" ,
200- stack_label = None , stack_ticklabels = None ):
199+ def ridgeline_plot (data , * , fig = None , overlap = 0.5 , xlabel = None , ylabel = "Per-line values" ,
200+ stack_label = None , stack_ticklabels = None ):
201201 """Make a ridgeline plot showing a sequence of similar lines
202202
203203 A ridgeline plot spreads out the different lines vertically to make their
@@ -208,6 +208,7 @@ def ridgeplot(data, *, overlap=0.5, xlabel=None, ylabel="Per-line values",
208208 data (array_like): A 2D array, each row of which will be plotted as one
209209 line, starting at the top of the plot. Pass an xarray DataArray to
210210 use its labels by default.
211+ fig (matplotlib.figure.Figure): Plot into an existing matplotlib figure.
211212 overlap (float): Number from 0 (no overlap) to 1, the fraction of each
212213 plot's area covered by the next plot.
213214 xlabel (str): Label for the shared x axis.
@@ -225,8 +226,10 @@ def ridgeplot(data, *, overlap=0.5, xlabel=None, ylabel="Per-line values",
225226 if data .ndim != 2 :
226227 raise TypeError (f"Expected a 2D array (got { data .ndim } D)" )
227228
229+ if fig is None :
230+ fig = plt .figure (figsize = (8 , 6 ), layout = "constrained" )
231+
228232 gs = grid_spec .GridSpec (len (data ), 1 , hspace = - overlap )
229- fig = plt .figure (figsize = (8 , 6 ))
230233
231234 if _isinstance_no_import (data , "xarray" , "DataArray" ):
232235 x_data = data .coords [data .dims [1 ]]
@@ -275,5 +278,4 @@ def ridgeplot(data, *, overlap=0.5, xlabel=None, ylabel="Per-line values",
275278
276279 if stack_label :
277280 fig .supylabel (stack_label , x = 1. , ha = "right" )
278- fig .tight_layout ()
279281 return fig
0 commit comments