|
11 | 11 | from ..plot import Plot |
12 | 12 | from ..layouts import GridPlot |
13 | 13 | from ..graphics import ImageGraphic |
14 | | -from ..utils import quick_min_max |
| 14 | +from ..utils import quick_min_max, calculate_gridshape |
15 | 15 |
|
16 | 16 |
|
17 | 17 | DEFAULT_DIMS_ORDER = \ |
|
23 | 23 | } |
24 | 24 |
|
25 | 25 |
|
26 | | -def _calc_gridshape(n): |
27 | | - sr = np.sqrt(n) |
28 | | - return ( |
29 | | - int(np.round(sr)), |
30 | | - int(np.ceil(sr)) |
31 | | - ) |
32 | | - |
33 | | - |
34 | 26 | def _is_arraylike(obj) -> bool: |
35 | 27 | """ |
36 | 28 | Checks if the object is array-like. |
@@ -248,11 +240,11 @@ def __init__( |
248 | 240 | # verify that it's a list of np.ndarray |
249 | 241 | if all([_is_arraylike(d) for d in data]): |
250 | 242 | if grid_shape is None: |
251 | | - grid_shape = _calc_gridshape(len(data)) |
| 243 | + grid_shape = calculate_gridshape(len(data)) |
252 | 244 |
|
253 | 245 | # verify that user-specified grid shape is large enough for the number of image arrays passed |
254 | 246 | elif grid_shape[0] * grid_shape[1] < len(data): |
255 | | - grid_shape = _calc_gridshape(len(data)) |
| 247 | + grid_shape = calculate_gridshape(len(data)) |
256 | 248 | warn(f"Invalid `grid_shape` passed, setting grid shape to: {grid_shape}") |
257 | 249 |
|
258 | 250 | _ndim = [d.ndim for d in data] |
@@ -821,11 +813,22 @@ def _set_slider_layout(self, *args): |
821 | 813 | for mm in self.vmin_vmax_sliders: |
822 | 814 | mm.layout = Layout(width=f"{w}px") |
823 | 815 |
|
824 | | - def _get_vmin_vmax_range(self, data: np.ndarray) -> Tuple[int, int]: |
| 816 | + def _get_vmin_vmax_range(self, data: np.ndarray) -> tuple: |
| 817 | + """ |
| 818 | + Parameters |
| 819 | + ---------- |
| 820 | + data |
| 821 | +
|
| 822 | + Returns |
| 823 | + ------- |
| 824 | + Tuple[Tuple[float, float], float, float, float] |
| 825 | + (min, max), data_range, min - (data_range * 0.4), max + (data_range * 0.4) |
| 826 | + """ |
| 827 | + |
825 | 828 | minmax = quick_min_max(data) |
826 | 829 |
|
827 | 830 | data_range = np.ptp(minmax) |
828 | | - data_range_40p = np.ptp(minmax) * 0.4 |
| 831 | + data_range_40p = data_range * 0.4 |
829 | 832 |
|
830 | 833 | _range = ( |
831 | 834 | minmax, |
|
0 commit comments