code: def _visual_filter(bounds, x, z=None, rtol=1e-8, ptol=1e-8):
      """apply a visual filter specified by bounds to the data within the monitor
  
      bounds: a string specifying bounds (e.g. "0:1:.1, 0:1:.1, .5, .5, .5")
      x: an array of shape (npts, params) with one param per bound
      z: an array of shape (npts,) of cost
      rtol: float (or list[float]) of max distance beyond range defined in bounds
      ptol: float (or list[float]) of max distance from fixed plane in bounds
  
      returns (x,z) filtered by ptol and rtol within the defined bounds
      """
      # Possible input for (x,y):
      #   paramlog.py: x,y => (1,xi,N,1),(1,N)
      #   log.txt: x,y => (N,xi),(N,)
      #   multilog.txt: x,y => (i,j),(i,); yi is list[float], yi => (Ni,); j => xi
      #                 xij is list[tuple[float]], xij => (Ni,) of length-1 tuple
      _x = getattr(x, "_x", x)  # params (x)
      _y = x._y if z is None else z  # cost (f(x))
      select, spec, mask = _parse_input(bounds)
      import numpy as np
  
      if rtol is not None:
          minmax = [s.strip().split(":")[:2] for s in spec.split(",")]
          minmax = np.array(
              [tuple(float(i) for i in mm) for mm in minmax]
          ).T
      else:
          minmax = (-np.inf, np.inf)
  
      # logical_and for distance within tolerance of selected cuts into hypercube
      _x = np.array(_x)
      xshape = _x.shape
      _y = np.array(_y)
      # yshape = _y.shape
      iterate = _y.dtype is np.dtype("O")
      reshape = True if (iterate or len(xshape) > 2) else False
      if iterate:  # 2D ndarray of lists of 1D tuple
          _x = [np.array([np.array(i) for i in xi]) for xi in _x]
          _y = [np.array(yi) for yi in _y]
      elif reshape:  # 4D ndarray
          _x = list(_x)
          _y = list(_y)
      else:  # 2D ndarray
          _x = [_x]
          _y = [_y]
      # we can now iterate over _x,_y in all cases (iterate,reshape are same)
      for i, (xi, yi) in enumerate(zip(_x, _y)):
          ok = True
          if reshape:
              xi = xi.squeeze().T
              yi = yi.squeeze().T
          if ptol is not None:
              ok = (abs(xi[:, mask.keys()] - mask.values()) < ptol).all(
                  axis=1
              )
          # logical_and for points within tolerance of selected bounds
          if rtol is not None:
              ok = (
                  (minmax[0] - rtol <= xi[:, select]).all(axis=1)
                  & (xi[:, select] <= minmax[1] + rtol).all(axis=1)
                  & ok
              )
  
          if ok is not True:  # skip filtering when all are valid
              xi = xi[ok]
              # ALT: yi[ok] = np.nan
              # apply same filter to cost
              yi = yi[ok]
              # ALT: yi[ok] = np.nan
  
          # reshape, then save to ith element of _x,_y
          # new shape is currently (-1,xi), (-1,) where N=-1
          if reshape:
              _x[i] = xi[None].T.tolist()  # (xi,N,1)
              _y[i] = yi.T.tolist()
          else:
              _x[i] = xi
              _y[i] = yi
  
      del xi, yi
      if not reshape:
          _x = _x[0]
          _y = _y[0]
      # return _x,_y (unless a monitor was provided)
      if z is not None:
          return _x, _y
  
      # if a monitor was provided, return a monitor
      m = x.__class__()
      m._x = _x
      m._y = _y
      m._id = x._id[:] if ok is True else np.array(x._id)[ok].tolist()
      # ALT: m._id = x._id
      m._info = x._info[:]
      # put rtol and ptol into a single sequence (for printing in info)
      tol = np.zeros(len(mask) + len(select))
      tol[mask.keys()] = ptol
      tol[select] = rtol
      m.info('FILTERED: tol=%s on "%s"' % (str(tol), bounds))
      m.k = x.k  # XXX: copy?
      m._npts = x._npts  # XXX: copy?
      m.label = x.label  # XXX: copy?
      return m
  
imports: from collections.abc import Callable
label_desc: Use image node_id 16 for calling a global function with example usage: _visual_filter(bounds, x, z, rtol, ptol) and returns: m, _x,  _y