def dynspread(img, threshold=0.5, max_px=3, shape='circle', how='over'):
    """Spread pixels in an image dynamically based on the image density.

    Spreading expands each pixel a certain number of pixels on all sides
    according to a given shape, merging pixels using a specified compositing
    operator. This can be useful to make sparse plots more visible. Dynamic
    spreading determines how many pixels to spread based on a density
    heuristic.

    Parameters
    ----------
    img : Image
    threshold : float, optional
        A tuning parameter in [0, 1]. Indicates the minimum value for the
        density heuristic.
    max_px : int, optional
        Maximum number of pixels to spread on all sides.
    shape : str, optional
        The shape to spread by. Options are 'circle' [default] or 'square'.
    how : str, optional
        The name of the compositing operator to use when combining pixels.
    """
    if not 0 <= threshold <= 1:
        raise ValueError("threshold must be in [0, 1]")
    if not isinstance(max_px, int) or max_px < 0:
        raise ValueError("max_px must be >= 0")
    # Simple linear search. Not super efficient, but max_px is usually small.
    for px in range(max_px + 1):
        out = spread(img, px, shape=shape, how=how)
        if _density(out.data) >= threshold:
            break
    return out
dataset/ETHPy150Open bokeh/datashader/datashader/transfer_functions.py/dynspread/original