Skip to content

Commit e78e7bf

Browse files
committed
Add x-lim slider
1 parent 50246f8 commit e78e7bf

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

panel/simdec.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def create_color_pickers(states, colors):
185185
@pn.cache
186186
def palette(res, colors_picked):
187187
cmaps = [single_color_to_colormap(color_picked) for color_picked in colors_picked]
188+
# Reverse order as in figures high values take the first colors
188189
return sd.palette(res.states[::-1], cmaps=cmaps[::-1])
189190

190191

@@ -200,14 +201,20 @@ def display_n_bins(kind):
200201

201202

202203
@pn.cache
203-
def figure(res, palette, n_bins, kind, output_name):
204+
def xlim_auto(res):
205+
return (np.min(res.bin_edges), np.max(res.bin_edges))
206+
207+
208+
@pn.cache
209+
def figure(res, palette, n_bins, xlim, kind, output_name):
204210
kind = "histogram" if kind == "Stacked histogram" else "boxplot"
205211
plt.close("all")
206212
fig, ax = plt.subplots()
207213
_ = sd.visualization(
208214
bins=res.bins, palette=palette, n_bins=n_bins, kind=kind, ax=ax
209215
)
210216
ax.set(xlabel=output_name)
217+
ax.set_xlim(xlim)
211218
return fig
212219

213220

@@ -346,6 +353,15 @@ def csv_data(
346353
visible=show_n_bins,
347354
)
348355

356+
interactive_xlim = pn.bind(xlim_auto, interactive_decomposition)
357+
selector_xlim = pn.widgets.EditableRangeSlider(
358+
name="X-lim",
359+
start=interactive_xlim.rx()[0],
360+
end=interactive_xlim.rx()[1],
361+
value=interactive_xlim,
362+
step=0.1,
363+
)
364+
349365
interactive_states = pn.bind(
350366
states_from_data, interactive_decomposition, interactive_inputs_decomposition
351367
)
@@ -377,6 +393,7 @@ def csv_data(
377393
interactive_decomposition,
378394
interactive_palette,
379395
selector_n_bins,
396+
selector_xlim,
380397
switch_histogram_boxplot,
381398
selector_output,
382399
)
@@ -402,6 +419,7 @@ def csv_data(
402419
pn.pane.Markdown("## Visualization", styles={"color": blue_color}),
403420
switch_histogram_boxplot,
404421
selector_n_bins,
422+
selector_xlim,
405423
dummy_color_pickers_bind,
406424
color_pickers,
407425
sizing_mode="stretch_width",

0 commit comments

Comments
 (0)