def hist2D(x, y, bin_type=None, bins=None, dens=True, scale=None, c=None,
    cstat=None, xlim=None, ylim=None, clim=[None, None], nmin=0, xinvert=
    False, yinvert=False, cbar_invert=False, xlog=False, ylog=False, clog=
    None, title=None, xlabel=None, ylabel=None, clabel=None, lab_loc=0, ax=
    None, grid=None, output=None, plot_kw={}, **kwargs):
    """2D histogram function.
	
	Parameters
	----------
	x : array-like
		Position of data points in the x axis.
	y : array-like
		Position of data points in the y axis.
	bin_type : {'number','width','edges','equal'}, optional
		Defines how is understood the value given in bins: 'number' for givinf the desired number of bins, 'width' for
		the width of the bins, 'edges' for the edges of bins, and 'equal' for making bins with equal number of elements
		(or as close as possible). If not given it is inferred from the data type of bins: 'number' if int, 'width' if
		float and 'edges' if ndarray.
	bins : int, float, array-like or list, optional
		Gives the values for the bins, according to bin_type.
	dens : bool or list, optional
		If false the histogram returns raw counts.
	scale : float or list, optional
		Scaling of the data counts.
	c : array-like, optional
		If a valid argument is given in cstat, defines the value used for the binned statistics.
	cstat : str or function, optional
		Must be one of the valid str arguments for the statistics variable in scipy.stats.binned_statistic_2d
		('mean’, 'median’, 'count’, 'sum’, 'min’ or 'max’) or a function that takes a 1D array and outputs an integer
		 or float.
	xlim : tuple-like, optional
		Defines the limits of the x-axis, it must contain two elements (lower and higer limits).
	ylim : tuple-like, optional
		Defines the limits of the y-axis, it must contain two elements (lower and higer limits).
	clim : list, optional
		Defines the limits of the colour map ranges, it must contain two elements (lower and higer limits).
	nmin : int, optional (default: 0)
		The minimum number of points required in a bin in order to be plotted.
	xinvert : bool, optional
		If True, inverts the x-axis.
	yinvert : bool, optional
		If True, inverts the y-axis.
	cbar_invert : bool, optional
		If True, inverts the direction of the colour bar (not the colour map).
	xlog : bool, optional
		If True, the scale of the x-axis is logarithmic.
	ylog : bool, optional
		If True, the scale of the x-axis is logarithmic.
	clog : bool, optional
		If True, the colour map is changed from linear to logarithmic.
	title : str, optional
		Sets the title of the plot
	xlabel : str, optional
		Sets the label of the x-axis.
	ylabel : str, optional
		Sets the label of the y-axis.
	clabel : str, optional
		Sets the legend for the colour axis.
	lab_loc : int, optional
		Defines the position of the legend
	ax : pyplot.Axes, optional
		Use the given axes to make the plot, defaults to the current axes.
	grid : boolean, optional
		If not given defaults to the value defined in splotch.Params.
	output : boolean, optional
		If True, returns the edges and values of the histogram.
	plot_kw : dict, optional
		Explicit dictionary of kwargs to be parsed to matplotlib scatter function.
		Parameters will be overwritten if also given implicitly as a **kwarg.
	**kwargs : pcolormesh properties, optional
		kwargs are used to specify matplotlib specific properties such as cmap, norm, edgecolors etc.
		https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolormesh.html

	Returns
	-------
	n : array
		The values of the histogram. Only provided if output is True.
	bin_edges_x : array
		The bin edges for the x axis. Only provided if output is True.
	bin_edges_y : array
		The bin edges for the y axis. Only provided if output is True.
	"""
    from numpy import nan, size, zeros, shape
    from matplotlib.colors import LogNorm
    from matplotlib.pyplot import pcolormesh, colorbar
    from .base_func import axes_handler, basehist2D, plot_finalizer
    if ax is not None:
        old_axes = axes_handler(ax)
    if type(bin_type) is not list:
        bin_type = [bin_type] * 2
    if type(bins) not in [list, tuple]:
        if bins is None:
            bins = max([10, int(len(x) ** 0.4)])
        bins = [bins] * 2
    if None in (clog, output):
        from .defaults import Params
        if clog is None:
            clog = Params.hist2D_caxis_log
        if output is None:
            output = Params.hist2D_output
    if size([x, y]) == 0:
        if clog == True:
            raise ValueError("Cannot set 'clog'=True if zero-size array given."
                )
        if cstat != None:
            raise ValueError(
                f"Cannot compute statistic (cstat='{cstat}') on zero-size array, set cstat=None if no data given."
                )
    X, Y, Z = basehist2D(x, y, c, bin_type, bins, scale, dens, cstat, xlog,
        ylog)
    if size([x, y]) == 0:
        counts = zeros(shape=shape(Z))
    else:
        _, _, counts = basehist2D(x, y, c, bin_type, bins, scale, dens,
            'count', xlog, ylog)
    Z[counts < nmin] = nan
    plot_par = plot_kw.copy()
    plot_par.update(kwargs)
    if clog:
        pcolormesh(X, Y, Z.T, norm=LogNorm(vmin=clim[0], vmax=clim[1], clip
            =True), **plot_par)
    else:
        pcolormesh(X, Y, Z.T, vmin=clim[0], vmax=clim[1], **plot_par)
    if clabel is not None:
        cbar = colorbar()
        cbar.set_label(clabel)
        if cbar_invert:
            cbar.ax.invert_yaxis()
    plot_finalizer(xlog, ylog, xlim, ylim, title, xlabel, ylabel, xinvert,
        yinvert, grid)
    if ax is not None:
        old_axes = axes_handler(old_axes)
    if output:
        return Z.T, X, Y
