import itertools


def plot_combinations_as_grid(axis, values, num_entries, bounds=None, **kwargs):
    """Take values from a grid and plot them as an image.

    Takes values generated from `linearly_spaced_combinations`.

    Parameters
    ----------
    axis: matplotlib.AxesSubplot.
    values: ndarray.
    num_entries: array_like.
        Number of samples to use for every dimension.
        Used for reshaping
    bounds: sequence of tuples.
        The bounds for the variables, [(x1_min, x1_max), (x2_min, x2_max), ...]
    kwargs: dict.
        Passed to axis.imshow
    """
    kwargs["origin"] = "lower"
    if bounds is not None:
        kwargs["extent"] = list(itertools.chain(*bounds))
    return axis.imshow(values.reshape(*num_entries).T, **kwargs)