qcodes/utils/plotting.py
def apply_color_scale_limits(colorbar: matplotlib.colorbar.Colorbar,
                             new_lim: Tuple[Optional[float], Optional[float]],
                             data_lim: Optional[Tuple[float, float]] = None,
                             data_array: Optional[np.ndarray] = None,
                             color_over: Optional[Any] = DEFAULT_COLOR_OVER,
                             color_under: Optional[Any] = DEFAULT_COLOR_UNDER
                             ) -> None:
    """
    Applies limits to colorscale and updates extend.

    This function applies the limits `new_lim` to the heatmap plot associated
    with the provided `colorbar`, updates the colorbar limits, and also adds
    the colorbar clipping indicators in form of small triangles on the top and
    bottom of the colorbar, according to where the limits are exceeded.

    Args:
        colorbar: The actual colorbar to be updated.
        new_lim: 2-tuple of the desired minimum and maximum value of the color
            scale. If any is `None` it will be left unchanged.
        data_lim: 2-tuple of the actual minimum and maximum value of the data.
            If left out the minimum and maximum are deduced from the provided
            data, or the data associated with the colorbar.
        data_array: Numpy array containing the data to be considered for
            scaling. Must be left out if `data_lim` is provided. If neither is
            provided the data associated with the colorbar is used.
        color_over: Matplotlib color representing the datapoints clipped by the
            upper limit.
        color_under: Matplotlib color representing the datapoints clipped by
            the lower limit.

    Raise:
        RuntimeError: If not received mesh data. Or if you specified both
        `data_lim` and `data_array`.
    """
    # browse the input data and make sure that `data_lim` and `new_lim` are
    # available
    if not isinstance(colorbar.mappable, matplotlib.collections.QuadMesh):
        raise RuntimeError('Can only scale mesh data, but received '
                           f'"{type(colorbar.mappable)}" instead')
    if data_lim is None:
        if data_array is None:
            data_array = colorbar.mappable.get_array()
        data_lim = np.nanmin(data_array), np.nanmax(data_array)
    else:
        if data_array is not None:
            raise RuntimeError('You may not specify `data_lim` and `data_array` '
                               'at the same time. Please refer to the docstring of '
                               '`apply_color_scale_limits for details:\n\n`'
                               + str(apply_color_scale_limits.__doc__))
        else:
            data_lim = cast(Tuple[float, float], tuple(sorted(data_lim)))
    # if `None` is provided in the new limits don't change this limit
    vlim = [new or old for new, old in zip(new_lim, colorbar.mappable.get_clim())]
    # sort limits in case they were given in a wrong order
    vlim = sorted(vlim)
    # detect exceeding colorscale and apply new limits
    exceeds_min, exceeds_max = (data_lim[0] < vlim[0],
                                data_lim[1] > vlim[1])
    if exceeds_min and exceeds_max:
        extend = 'both'
    elif exceeds_min:
        extend = 'min'
    elif exceeds_max:
        extend = 'max'
    else:
        extend = 'neither'
    _set_colorbar_extend(colorbar, extend)
    cmap = copy.copy(colorbar.mappable.get_cmap())
    cmap.set_over(color_over)
    cmap.set_under(color_under)
    colorbar.mappable.set_cmap(cmap)
    colorbar.mappable.set_clim(vlim)

    Applies limits to colorscale and updates extend.

    This function applies the limits `new_lim` to the heatmap plot associated
    with the provided `colorbar`, updates the colorbar limits, and also adds
    the colorbar clipping indicators in form of small triangles on the top and
    bottom of the colorbar, according to where the limits are exceeded.

    Args:
        colorbar: The actual colorbar to be updated.
        new_lim: 2-tuple of the desired minimum and maximum value of the color
            scale. If any is `None` it will be left unchanged.
        data_lim: 2-tuple of the actual minimum and maximum value of the data.
            If left out the minimum and maximum are deduced from the provided
            data, or the data associated with the colorbar.
        data_array: Numpy array containing the data to be considered for
            scaling. Must be left out if `data_lim` is provided. If neither is
            provided the data associated with the colorbar is used.
        color_over: Matplotlib color representing the datapoints clipped by the
            upper limit.
        color_under: Matplotlib color representing the datapoints clipped by
            the lower limit.

    Raise:
        RuntimeError: If not received mesh data. Or if you specified both
        `data_lim` and `data_array`.
    
Applies limits to colorscale and updates extend.
This function applies the limits `new_lim` to the heatmap plot associated
with the provided `colorbar`, updates the colorbar limits, and also adds
the colorbar clipping indicators in form of small triangles on the top and
bottom of the colorbar, according to where the limits are exceeded.
Applies limits to colorscale and updates extend . This function applies the limits ` new_lim ` to the heatmap plot associated with the provided ` colorbar ` updates the colorbar limits and also adds the colorbar clipping indicators in form of small triangles on the top and bottom of the colorbar according to where the limits are exceeded .
def apply_color_scale_limits(colorbar: matplotlib.colorbar.Colorbar,
                             new_lim: Tuple[Optional[float], Optional[float]],
                             data_lim: Optional[Tuple[float, float]] = None,
                             data_array: Optional[np.ndarray] = None,
                             color_over: Optional[Any] = DEFAULT_COLOR_OVER,
                             color_under: Optional[Any] = DEFAULT_COLOR_UNDER
                             ) -> None:
    if not isinstance(colorbar.mappable, matplotlib.collections.QuadMesh):
        raise RuntimeError('Can only scale mesh data, but received '
                           f'"{type(colorbar.mappable)}" instead')
    if data_lim is None:
        if data_array is None:
            data_array = colorbar.mappable.get_array()
        data_lim = np.nanmin(data_array), np.nanmax(data_array)
    else:
        if data_array is not None:
            raise RuntimeError('You may not specify `data_lim` and `data_array` '
                               'at the same time. Please refer to the docstring of '
                               '`apply_color_scale_limits for details:\n\n`'
                               + str(apply_color_scale_limits.__doc__))
        else:
            data_lim = cast(Tuple[float, float], tuple(sorted(data_lim)))
    vlim = [new or old for new, old in zip(new_lim, colorbar.mappable.get_clim())]
    vlim = sorted(vlim)
    exceeds_min, exceeds_max = (data_lim[0] < vlim[0],
                                data_lim[1] > vlim[1])
    if exceeds_min and exceeds_max:
        extend = 'both'
    elif exceeds_min:
        extend = 'min'
    elif exceeds_max:
        extend = 'max'
    else:
        extend = 'neither'
    _set_colorbar_extend(colorbar, extend)
    cmap = copy.copy(colorbar.mappable.get_cmap())
    cmap.set_over(color_over)
    cmap.set_under(color_under)
    colorbar.mappable.set_cmap(cmap)
    colorbar.mappable.set_clim(vlim)
def apply_color_scale_limits ( colorbar : matplotlib . colorbar . Colorbar , new_lim : Tuple [ Optional [ float ] , Optional [ float ] ] , data_lim : Optional [ Tuple [ float , float ] ] = None , data_array : Optional [ np . ndarray ] = None , color_over : Optional [ Any ] = DEFAULT_COLOR_OVER , color_under : Optional [ Any ] = DEFAULT_COLOR_UNDER ) -> None : if not isinstance ( colorbar . mappable , matplotlib . collections . QuadMesh ) : raise RuntimeError ( 'Can only scale mesh data, but received ' f'"{type(colorbar.mappable)}" instead' ) if data_lim is None : if data_array is None : data_array = colorbar . mappable . get_array ( ) data_lim = np . nanmin ( data_array ) , np . nanmax ( data_array ) else : if data_array is not None : raise RuntimeError ( 'You may not specify `data_lim` and `data_array` ' 'at the same time. Please refer to the docstring of ' '`apply_color_scale_limits for details:\n\n`' + str ( apply_color_scale_limits . __doc__ ) ) else : data_lim = cast ( Tuple [ float , float ] , tuple ( sorted ( data_lim ) ) ) vlim = [ new or old for new , old in zip ( new_lim , colorbar . mappable . get_clim ( ) ) ] vlim = sorted ( vlim ) exceeds_min , exceeds_max = ( data_lim [ 0 ] < vlim [ 0 ] , data_lim [ 1 ] > vlim [ 1 ] ) if exceeds_min and exceeds_max : extend = 'both' elif exceeds_min : extend = 'min' elif exceeds_max : extend = 'max' else : extend = 'neither' _set_colorbar_extend ( colorbar , extend ) cmap = copy . copy ( colorbar . mappable . get_cmap ( ) ) cmap . set_over ( color_over ) cmap . set_under ( color_under ) colorbar . mappable . set_cmap ( cmap ) colorbar . mappable . set_clim ( vlim )
Applies limits to colorscale and updates extend.
Applies limits to colorscale and updates extend .
"""
    Applies limits to colorscale and updates extend.

    This function applies the limits `new_lim` to the heatmap plot associated
    with the provided `colorbar`, updates the colorbar limits, and also adds
    the colorbar clipping indicators in form of small triangles on the top and
    bottom of the colorbar, according to where the limits are exceeded.

    Args:
        colorbar: The actual colorbar to be updated.
        new_lim: 2-tuple of the desired minimum and maximum value of the color
            scale. If any is `None` it will be left unchanged.
        data_lim: 2-tuple of the actual minimum and maximum value of the data.
            If left out the minimum and maximum are deduced from the provided
            data, or the data associated with the colorbar.
        data_array: Numpy array containing the data to be considered for
            scaling. Must be left out if `data_lim` is provided. If neither is
            provided the data associated with the colorbar is used.
        color_over: Matplotlib color representing the datapoints clipped by the
            upper limit.
        color_under: Matplotlib color representing the datapoints clipped by
            the lower limit.

    Raise:
        RuntimeError: If not received mesh data. Or if you specified both
        `data_lim` and `data_array`.
    """ # browse the input data and make sure that `data_lim` and `new_lim` are # available # if `None` is provided in the new limits don't change this limit # sort limits in case they were given in a wrong order # detect exceeding colorscale and apply new limits
colorbar
matplotlib.colorbar.Colorbar
The actual colorbar to be updated.
The actual colorbar to be updated .
new_lim
Tuple[Optional[float], Optional[float]]
2-tuple of the desired minimum and maximum value of the color
scale. If any is `None` it will be left unchanged.
2 - tuple of the desired minimum and maximum value of the color scale . If any is ` None ` it will be left unchanged .
data_lim
Optional[Tuple[float, float]]
2-tuple of the actual minimum and maximum value of the data.
If left out the minimum and maximum are deduced from the provided
data, or the data associated with the colorbar.
2 - tuple of the actual minimum and maximum value of the data . If left out the minimum and maximum are deduced from the provided data or the data associated with the colorbar .
data_array
Optional[np.ndarray]
Numpy array containing the data to be considered for
scaling. Must be left out if `data_lim` is provided. If neither is
provided the data associated with the colorbar is used.
Numpy array containing the data to be considered for scaling . Must be left out if ` data_lim ` is provided . If neither is provided the data associated with the colorbar is used .
color_over
Optional[Any]
Matplotlib color representing the datapoints clipped by the
upper limit.
Matplotlib color representing the datapoints clipped by the upper limit .
color_under
Optional[Any]
Matplotlib color representing the datapoints clipped by
the lower limit.
Matplotlib color representing the datapoints clipped by the lower limit .