Skip to content

Commit 75b7d73

Browse files
committed
restore y-padding on rectangle selector limits, refactored to also work when ymin is positive
1 parent c5ec080 commit 75b7d73

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fastplotlib/graphics/_positions_base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,17 @@ def add_rectangle_selector(
291291

292292
ymin = np.floor(y_axis_vals.min()).astype(int)
293293
ymax = np.ceil(y_axis_vals.max()).astype(int)
294+
y25p = 0.25 * (ymax - ymin)
294295
xmin = np.floor(x_axis_vals.min()).astype(int)
295296
xmax = np.ceil(x_axis_vals.max()).astype(int)
297+
x25p = 0.25 * (xmax - xmin)
296298

297299
# default selection is 25% of the image
298300
if selection is None:
299-
selection = (xmin, xmin + 0.25 * (xmax - xmin), ymin, ymax)
301+
selection = (xmin, xmin + x25p, ymin, ymax)
300302

301-
# min/max limits
302-
limits = (xmin, xmax, ymin, ymax)
303+
# min/max limits include the data + 25% padding in the y-direction
304+
limits = (xmin, xmax, ymin - y25p, ymax + y25p)
303305

304306
selector = RectangleSelector(
305307
selection=selection,
@@ -332,7 +334,7 @@ def _get_linear_selector_init_args(
332334
magn_vals = data[:, 0]
333335

334336
axis_vals_min = np.floor(axis_vals.min()).astype(int)
335-
axis_vals_max = np.floor(axis_vals.max()).astype(int)
337+
axis_vals_max = np.ceil(axis_vals.max()).astype(int)
336338
axis_vals_25p = axis_vals_min + 0.25 * (axis_vals_max - axis_vals_min)
337339

338340
# default selection is 25% of the image

0 commit comments

Comments
 (0)