qcodes/dataset/plotting.py
def plot_on_a_plain_grid(x: np.ndarray,
                         y: np.ndarray,
                         z: np.ndarray,
                         ax: matplotlib.axes.Axes,
                         colorbar: matplotlib.colorbar.Colorbar = None,
                         **kwargs: Any
                         ) -> AxesTuple:
    """
    Plot a heatmap of z using x and y as axes. Assumes that the data
    are rectangular, i.e. that x and y together describe a rectangular
    grid. The arrays of x and y need not be sorted in any particular
    way, but data must belong together such that z[n] has x[n] and
    y[n] as setpoints.  The setpoints need not be equidistantly
    spaced, but linear interpolation is used to find the edges of the
    plotted squares. ``**kwargs`` are passed to matplotlib's pcolormesh used
    for the plotting. By default the data in any vector plot will be rasterized
    if more that 5000 points are supplied. This can be overridden
    by supplying the `rasterized` kwarg.

    Args:
        x: The x values
        y: The y values
        z: The z values
        ax: The axis to plot onto
        colorbar: A colorbar to reuse the axis for

    Returns:
        The matplotlib axes handle for plot and colorbar
    """

    log.debug(f'Got kwargs: {kwargs}')

    x_is_stringy = isinstance(x[0], str)
    y_is_stringy = isinstance(y[0], str)
    z_is_stringy = isinstance(z[0], str)

    if x_is_stringy:
        x_strings = np.unique(x)
        x = _strings_as_ints(x)

    if y_is_stringy:
        y_strings = np.unique(y)
        y = _strings_as_ints(y)

    if z_is_stringy:
        z_strings = np.unique(z)
        z = _strings_as_ints(z)

    if x.ndim == 2 and y.ndim == 2 and z.ndim == 2:
        if not np.logical_or(np.any(np.isnan(x)), np.any(np.isnan(y))):
            # data is on a grid that may or may not be
            # rectilinear. Rely on matplotlib to plot
            # this directly
            x_to_plot, y_to_plot, z_to_plot = x, y, z
            num_points = x_to_plot.size
        else:
            x_to_plot, y_to_plot, z_to_plot = _clip_nan_from_shaped_data(x, y, z)
            num_points = x_to_plot.size * y_to_plot.size
    else:
        x_to_plot, y_to_plot, z_to_plot = reshape_2D_data(x, y, z)
        num_points = x_to_plot.size * y_to_plot.size

    if 'rasterized' in kwargs.keys():
        rasterized = kwargs.pop('rasterized')
    else:
        rasterized = num_points > qc.config.plotting.rasterize_threshold

    cmap = kwargs.pop('cmap') if 'cmap' in kwargs else None

    if z_is_stringy:
        name = cmap.name if hasattr(cmap, 'name') else 'viridis'
        cmap = matplotlib.cm.get_cmap(name, len(z_strings))

    colormesh = ax.pcolormesh(
        x_to_plot,
        y_to_plot,
        np.ma.masked_invalid(z_to_plot),
        rasterized=rasterized,
        cmap=cmap,
        shading="nearest",
        **kwargs,
    )

    if x_is_stringy:
        ax.set_xticks(np.arange(len(np.unique(x_strings))))
        ax.set_xticklabels(x_strings)

    if y_is_stringy:
        ax.set_yticks(np.arange(len(np.unique(y_strings))))
        ax.set_yticklabels(y_strings)

    if colorbar is not None:
        colorbar = ax.figure.colorbar(colormesh, ax=ax, cax=colorbar.ax)
    else:
        colorbar = ax.figure.colorbar(colormesh, ax=ax)

    if z_is_stringy:
        N = len(z_strings)
        f = (N-1)/N
        colorbar.set_ticks([(n+0.5)*f for n in range(N)])
        colorbar.set_ticklabels(z_strings)

    return ax, colorbar

    Plot a heatmap of z using x and y as axes. Assumes that the data
    are rectangular, i.e. that x and y together describe a rectangular
    grid. The arrays of x and y need not be sorted in any particular
    way, but data must belong together such that z[n] has x[n] and
    y[n] as setpoints.  The setpoints need not be equidistantly
    spaced, but linear interpolation is used to find the edges of the
    plotted squares. ``**kwargs`` are passed to matplotlib's pcolormesh used
    for the plotting. By default the data in any vector plot will be rasterized
    if more that 5000 points are supplied. This can be overridden
    by supplying the `rasterized` kwarg.

    Args:
        x: The x values
        y: The y values
        z: The z values
        ax: The axis to plot onto
        colorbar: A colorbar to reuse the axis for

    Returns:
        The matplotlib axes handle for plot and colorbar
    
Plot a heatmap of z using x and y as axes. Assumes that the data
are rectangular, i.e. that x and y together describe a rectangular
grid. The arrays of x and y need not be sorted in any particular
way, but data must belong together such that z[n] has x[n] and
y[n] as setpoints.  The setpoints need not be equidistantly
spaced, but linear interpolation is used to find the edges of the
plotted squares. ``**kwargs`` are passed to matplotlib's pcolormesh used
for the plotting. By default the data in any vector plot will be rasterized
if more that 5000 points are supplied. This can be overridden
by supplying the `rasterized` kwarg.
Plot a heatmap of z using x and y as axes . Assumes that the data are rectangular i . e . that x and y together describe a rectangular grid . The arrays of x and y need not be sorted in any particular way but data must belong together such that z [ n ] has x [ n ] and y [ n ] as setpoints . The setpoints need not be equidistantly spaced but linear interpolation is used to find the edges of the plotted squares . ` ` ** kwargs ` ` are passed to matplotlib ' s pcolormesh used for the plotting . By default the data in any vector plot will be rasterized if more that 5000 points are supplied . This can be overridden by supplying the ` rasterized ` kwarg .
def plot_on_a_plain_grid(x: np.ndarray,
                         y: np.ndarray,
                         z: np.ndarray,
                         ax: matplotlib.axes.Axes,
                         colorbar: matplotlib.colorbar.Colorbar = None,
                         **kwargs: Any
                         ) -> AxesTuple:
    log.debug(f'Got kwargs: {kwargs}')
    x_is_stringy = isinstance(x[0], str)
    y_is_stringy = isinstance(y[0], str)
    z_is_stringy = isinstance(z[0], str)
    if x_is_stringy:
        x_strings = np.unique(x)
        x = _strings_as_ints(x)
    if y_is_stringy:
        y_strings = np.unique(y)
        y = _strings_as_ints(y)
    if z_is_stringy:
        z_strings = np.unique(z)
        z = _strings_as_ints(z)
    if x.ndim == 2 and y.ndim == 2 and z.ndim == 2:
        if not np.logical_or(np.any(np.isnan(x)), np.any(np.isnan(y))):
            x_to_plot, y_to_plot, z_to_plot = x, y, z
            num_points = x_to_plot.size
        else:
            x_to_plot, y_to_plot, z_to_plot = _clip_nan_from_shaped_data(x, y, z)
            num_points = x_to_plot.size * y_to_plot.size
    else:
        x_to_plot, y_to_plot, z_to_plot = reshape_2D_data(x, y, z)
        num_points = x_to_plot.size * y_to_plot.size
    if 'rasterized' in kwargs.keys():
        rasterized = kwargs.pop('rasterized')
    else:
        rasterized = num_points > qc.config.plotting.rasterize_threshold
    cmap = kwargs.pop('cmap') if 'cmap' in kwargs else None
    if z_is_stringy:
        name = cmap.name if hasattr(cmap, 'name') else 'viridis'
        cmap = matplotlib.cm.get_cmap(name, len(z_strings))
    colormesh = ax.pcolormesh(
        x_to_plot,
        y_to_plot,
        np.ma.masked_invalid(z_to_plot),
        rasterized=rasterized,
        cmap=cmap,
        shading="nearest",
        **kwargs,
    )
    if x_is_stringy:
        ax.set_xticks(np.arange(len(np.unique(x_strings))))
        ax.set_xticklabels(x_strings)
    if y_is_stringy:
        ax.set_yticks(np.arange(len(np.unique(y_strings))))
        ax.set_yticklabels(y_strings)
    if colorbar is not None:
        colorbar = ax.figure.colorbar(colormesh, ax=ax, cax=colorbar.ax)
    else:
        colorbar = ax.figure.colorbar(colormesh, ax=ax)
    if z_is_stringy:
        N = len(z_strings)
        f = (N-1)/N
        colorbar.set_ticks([(n+0.5)*f for n in range(N)])
        colorbar.set_ticklabels(z_strings)
    return ax, colorbar
def plot_on_a_plain_grid ( x : np . ndarray , y : np . ndarray , z : np . ndarray , ax : matplotlib . axes . Axes , colorbar : matplotlib . colorbar . Colorbar = None , ** kwargs : Any ) -> AxesTuple : log . debug ( f'Got kwargs: {kwargs}' ) x_is_stringy = isinstance ( x [ 0 ] , str ) y_is_stringy = isinstance ( y [ 0 ] , str ) z_is_stringy = isinstance ( z [ 0 ] , str ) if x_is_stringy : x_strings = np . unique ( x ) x = _strings_as_ints ( x ) if y_is_stringy : y_strings = np . unique ( y ) y = _strings_as_ints ( y ) if z_is_stringy : z_strings = np . unique ( z ) z = _strings_as_ints ( z ) if x . ndim == 2 and y . ndim == 2 and z . ndim == 2 : if not np . logical_or ( np . any ( np . isnan ( x ) ) , np . any ( np . isnan ( y ) ) ) : x_to_plot , y_to_plot , z_to_plot = x , y , z num_points = x_to_plot . size else : x_to_plot , y_to_plot , z_to_plot = _clip_nan_from_shaped_data ( x , y , z ) num_points = x_to_plot . size * y_to_plot . size else : x_to_plot , y_to_plot , z_to_plot = reshape_2D_data ( x , y , z ) num_points = x_to_plot . size * y_to_plot . size if 'rasterized' in kwargs . keys ( ) : rasterized = kwargs . pop ( 'rasterized' ) else : rasterized = num_points > qc . config . plotting . rasterize_threshold cmap = kwargs . pop ( 'cmap' ) if 'cmap' in kwargs else None if z_is_stringy : name = cmap . name if hasattr ( cmap , 'name' ) else 'viridis' cmap = matplotlib . cm . get_cmap ( name , len ( z_strings ) ) colormesh = ax . pcolormesh ( x_to_plot , y_to_plot , np . ma . masked_invalid ( z_to_plot ) , rasterized = rasterized , cmap = cmap , shading = "nearest" , ** kwargs , ) if x_is_stringy : ax . set_xticks ( np . arange ( len ( np . unique ( x_strings ) ) ) ) ax . set_xticklabels ( x_strings ) if y_is_stringy : ax . set_yticks ( np . arange ( len ( np . unique ( y_strings ) ) ) ) ax . set_yticklabels ( y_strings ) if colorbar is not None : colorbar = ax . figure . colorbar ( colormesh , ax = ax , cax = colorbar . ax ) else : colorbar = ax . figure . colorbar ( colormesh , ax = ax ) if z_is_stringy : N = len ( z_strings ) f = ( N - 1 ) / N colorbar . set_ticks ( [ ( n + 0.5 ) * f for n in range ( N ) ] ) colorbar . set_ticklabels ( z_strings ) return ax , colorbar
Plot a heatmap of z using x and y as axes.
Plot a heatmap of z using x and y as axes .
"""
    Plot a heatmap of z using x and y as axes. Assumes that the data
    are rectangular, i.e. that x and y together describe a rectangular
    grid. The arrays of x and y need not be sorted in any particular
    way, but data must belong together such that z[n] has x[n] and
    y[n] as setpoints.  The setpoints need not be equidistantly
    spaced, but linear interpolation is used to find the edges of the
    plotted squares. ``**kwargs`` are passed to matplotlib's pcolormesh used
    for the plotting. By default the data in any vector plot will be rasterized
    if more that 5000 points are supplied. This can be overridden
    by supplying the `rasterized` kwarg.

    Args:
        x: The x values
        y: The y values
        z: The z values
        ax: The axis to plot onto
        colorbar: A colorbar to reuse the axis for

    Returns:
        The matplotlib axes handle for plot and colorbar
    """ # data is on a grid that may or may not be # rectilinear. Rely on matplotlib to plot # this directly
The matplotlib axes handle for plot and colorbar
The matplotlib axes handle for plot and colorbar
x
np.ndarray
The x values
The x values
y
np.ndarray
The y values
The y values
z
np.ndarray
The z values
The z values
ax
matplotlib.axes.Axes
The axis to plot onto
The axis to plot onto
colorbar
matplotlib.colorbar.Colorbar
A colorbar to reuse the axis for
A colorbar to reuse the axis for
kwargs
Any