# Buggy code
def newplotfunc(
    darray,
    x=None,
    y=None,
    figsize=None,
    size=None,
    aspect=None,
    ax=None,
    row=None,
    col=None,
    col_wrap=None,
    xincrease=True,
    yincrease=True,
    add_colorbar=None,
    add_labels=True,
    vmin=None,
    vmax=None,
    cmap=None,
    center=None,
    robust=False,
    extend=None,
    levels=None,
    infer_intervals=None,
    colors=None,
    subplot_kws=None,
    cbar_ax=None,
    cbar_kwargs=None,
    xscale=None,
    yscale=None,
    xticks=None,
    yticks=None,
    xlim=None,
    ylim=None,
    norm=None,
    **kwargs,
):
    # All 2d plots in xarray share this function signature.
    # Method signature below should be consistent.

    # Decide on a default for the colorbar before facetgrids
    if add_colorbar is None:
        add_colorbar = plotfunc.__name__ != "contour"
    imshow_rgb = plotfunc.__name__ == "imshow" and darray.ndim == (
        3 + (row is not None) + (col is not None)
    )
    if imshow_rgb:
        # Don't add a colorbar when showing an image with explicit colors
        add_colorbar = False
        # Matplotlib does not support normalising RGB data, so do it here.
        # See eg. https://github.com/matplotlib/matplotlib/pull/10220
        if robust or vmax is not None or vmin is not None:
            darray = _rescale_imshow_rgb(darray, vmin, vmax, robust)
            vmin, vmax, robust = None, None, False

    # Handle facetgrids first
    if row or col:
        allargs = locals().copy()
        del allargs["darray"]
        del allargs["imshow_rgb"]
        allargs.update(allargs.pop("kwargs"))
        # Need the decorated plotting function
        allargs["plotfunc"] = globals()[plotfunc.__name__]
        return _easy_facetgrid(darray, kind="dataarray", **allargs)

    plt = import_matplotlib_pyplot()

    rgb = kwargs.pop("rgb", None)
    if rgb is not None and plotfunc.__name__ != "imshow":
        raise ValueError('The "rgb" keyword is only valid for imshow()')
    elif rgb is not None and not imshow_rgb:
        raise ValueError(
            'The "rgb" keyword is only valid for imshow()'
            "with a three-dimensional array (per facet)"
        )

    xlab, ylab = _infer_xy_labels(darray=darray, x=x, y=y, imshow=imshow_rgb, rgb=rgb)

    # better to pass the ndarrays directly to plotting functions
    xval = darray[xlab].values
    yval = darray[ylab].values

    # check if we need to broadcast one dimension
    if xval.ndim < yval.ndim:
        dims = darray[ylab].dims
        if xval.shape[0] == yval.shape[0]:
            xval = np.broadcast_to(xval[:, np.newaxis], yval.shape)
        else:
            xval = np.broadcast_to(xval[np.newaxis, :], yval.shape)

    elif yval.ndim < xval.ndim:
        dims = darray[xlab].dims
        if yval.shape[0] == xval.shape[0]:
            yval = np.broadcast_to(yval[:, np.newaxis], xval.shape)
        else:
            yval = np.broadcast_to(yval[np.newaxis, :], xval.shape)
    elif xval.ndim == 2:
        dims = darray[xlab].dims
    else:
        dims = (darray[ylab].dims[0], darray[xlab].dims[0])

    # May need to transpose for correct x, y labels
    # xlab may be the name of a coord, we have to check for dim names
    if imshow_rgb:
        # For RGB[A] images, matplotlib requires the color dimension
        # to be last.  In Xarray the order should be unimportant, so
        # we transpose to (y, x, color) to make this work.
        yx_dims = (ylab, xlab)
        dims = yx_dims + tuple(d for d in darray.dims if d not in yx_dims)

    if dims != darray.dims:
        darray = darray.transpose(*dims, transpose_coords=True)

    # Pass the data as a masked ndarray too
    zval = darray.to_masked_array(copy=False)

    # Replace pd.Intervals if contained in xval or yval.
    xplt, xlab_extra = _resolve_intervals_2dplot(xval, plotfunc.__name__)
    yplt, ylab_extra = _resolve_intervals_2dplot(yval, plotfunc.__name__)

    _ensure_plottable(xplt, yplt)

    cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs(
        plotfunc, zval.data, **locals()
    )

    if "contour" in plotfunc.__name__:
        # extend is a keyword argument only for contour and contourf, but
        # passing it to the colorbar is sufficient for imshow and
        # pcolormesh
        kwargs["extend"] = cmap_params["extend"]
        kwargs["levels"] = cmap_params["levels"]
        # if colors == a single color, matplotlib draws dashed negative
        # contours. we lose this feature if we pass cmap and not colors
        if isinstance(colors, str):
            cmap_params["cmap"] = None
            kwargs["colors"] = colors

    if "pcolormesh" == plotfunc.__name__:
        kwargs["infer_intervals"] = infer_intervals

    if "imshow" == plotfunc.__name__ and isinstance(aspect, str):
        # forbid usage of mpl strings
        raise ValueError("plt.imshow's `aspect` kwarg is not available in xarray")

    ax = get_axis(figsize, size, aspect, ax)
    primitive = plotfunc(
        xplt,
        yplt,
        zval,
        ax=ax,
        cmap=cmap_params["cmap"],
        vmin=cmap_params["vmin"],
        vmax=cmap_params["vmax"],
        norm=cmap_params["norm"],
        **kwargs,
    )

    # Label the plot with metadata
    if add_labels:
        ax.set_xlabel(label_from_attrs(darray[xlab], xlab_extra))
        ax.set_ylabel(label_from_attrs(darray[ylab], ylab_extra))
        ax.set_title(darray._title_for_slice())

    if add_colorbar:
        if add_labels and "label" not in cbar_kwargs:
            cbar_kwargs["label"] = label_from_attrs(darray)
        cbar = _add_colorbar(primitive, ax, cbar_ax, cbar_kwargs, cmap_params)
    elif cbar_ax is not None or cbar_kwargs:
        # inform the user about keywords which aren't used
        raise ValueError(
            "cbar_ax and cbar_kwargs can't be used with add_colorbar=False."
        )

    # origin kwarg overrides yincrease
    if "origin" in kwargs:
        yincrease = None

    _update_axes(ax, xincrease, yincrease, xscale, yscale, xticks, yticks, xlim, ylim)

    # Rotate dates on xlabels
    # Do this without calling autofmt_xdate so that x-axes ticks
    # on other subplots (if any) are not deleted.
    # https://stackoverflow.com/questions/17430105/autofmt-xdate-deletes-x-axis-labels-of-all-subplots
    if np.issubdtype(xplt.dtype, np.datetime64):
        for xlabels in ax.get_xticklabels():
            xlabels.set_rotation(30)
            xlabels.set_ha("right")

    return primitive


# Traceback (TypeError)
TypeError                                 Traceback (most recent call last)
<ipython-input-22-d911786d1072> in <module>
----> 1 xarray.DataArray([True, False]).plot()

~/python_venvs/python3/py3_18.04/lib/python3.6/site-packages/xarray/plot/plot.py in __call__(self, **kwargs)
463
464     def __call__(self, **kwargs):
--> 465         return plot(self._da, **kwargs)
466
467     @functools.wraps(hist)

~/python_venvs/python3/py3_18.04/lib/python3.6/site-packages/xarray/plot/plot.py in plot(darray, row, col, col_wrap, ax, hue, rtol, subplot_kws, **kwargs)
200     kwargs["ax"] = ax
201
--> 202     return plotfunc(darray, **kwargs)
203
204

~/python_venvs/python3/py3_18.04/lib/python3.6/site-packages/xarray/plot/plot.py in line(darray, row, col, figsize, aspect, size, ax, hue, x, y, xincrease, yincrease, xscale, yscale, xticks, yticks, xlim, ylim, add_legend, _labels, *args, **kwargs)
321         yplt_val = yplt.values
322
--> 323     _ensure_plottable(xplt_val, yplt_val)
324
325     primitive = ax.plot(xplt_val, yplt_val, *args, **kwargs)

~/python_venvs/python3/py3_18.04/lib/python3.6/site-packages/xarray/plot/utils.py in _ensure_plottable(*args)
510         ):
511             raise TypeError(
--> 512                 "Plotting requires coordinates to be numeric "
513                 "or dates of type np.datetime64, "
514                 "datetime.datetime, cftime.datetime or "

TypeError: Plotting requires coordinates to be numeric or dates of type np.datetime64, datetime.datetime, cftime.datetime or pd.Interval.

# Fixed code
def newplotfunc(
    darray,
    x=None,
    y=None,
    figsize=None,
    size=None,
    aspect=None,
    ax=None,
    row=None,
    col=None,
    col_wrap=None,
    xincrease=True,
    yincrease=True,
    add_colorbar=None,
    add_labels=True,
    vmin=None,
    vmax=None,
    cmap=None,
    center=None,
    robust=False,
    extend=None,
    levels=None,
    infer_intervals=None,
    colors=None,
    subplot_kws=None,
    cbar_ax=None,
    cbar_kwargs=None,
    xscale=None,
    yscale=None,
    xticks=None,
    yticks=None,
    xlim=None,
    ylim=None,
    norm=None,
    **kwargs,
):
    # All 2d plots in xarray share this function signature.
    # Method signature below should be consistent.

    # Decide on a default for the colorbar before facetgrids
    if add_colorbar is None:
        add_colorbar = plotfunc.__name__ != "contour"
    imshow_rgb = plotfunc.__name__ == "imshow" and darray.ndim == (
        3 + (row is not None) + (col is not None)
    )
    if imshow_rgb:
        # Don't add a colorbar when showing an image with explicit colors
        add_colorbar = False
        # Matplotlib does not support normalising RGB data, so do it here.
        # See eg. https://github.com/matplotlib/matplotlib/pull/10220
        if robust or vmax is not None or vmin is not None:
            darray = _rescale_imshow_rgb(darray, vmin, vmax, robust)
            vmin, vmax, robust = None, None, False

    # Handle facetgrids first
    if row or col:
        allargs = locals().copy()
        del allargs["darray"]
        del allargs["imshow_rgb"]
        allargs.update(allargs.pop("kwargs"))
        # Need the decorated plotting function
        allargs["plotfunc"] = globals()[plotfunc.__name__]
        return _easy_facetgrid(darray, kind="dataarray", **allargs)

    plt = import_matplotlib_pyplot()

    rgb = kwargs.pop("rgb", None)
    if rgb is not None and plotfunc.__name__ != "imshow":
        raise ValueError('The "rgb" keyword is only valid for imshow()')
    elif rgb is not None and not imshow_rgb:
        raise ValueError(
            'The "rgb" keyword is only valid for imshow()'
            "with a three-dimensional array (per facet)"
        )

    xlab, ylab = _infer_xy_labels(darray=darray, x=x, y=y, imshow=imshow_rgb, rgb=rgb)

    # better to pass the ndarrays directly to plotting functions
    xval = darray[xlab].values
    yval = darray[ylab].values

    # check if we need to broadcast one dimension
    if xval.ndim < yval.ndim:
        dims = darray[ylab].dims
        if xval.shape[0] == yval.shape[0]:
            xval = np.broadcast_to(xval[:, np.newaxis], yval.shape)
        else:
            xval = np.broadcast_to(xval[np.newaxis, :], yval.shape)

    elif yval.ndim < xval.ndim:
        dims = darray[xlab].dims
        if yval.shape[0] == xval.shape[0]:
            yval = np.broadcast_to(yval[:, np.newaxis], xval.shape)
        else:
            yval = np.broadcast_to(yval[np.newaxis, :], xval.shape)
    elif xval.ndim == 2:
        dims = darray[xlab].dims
    else:
        dims = (darray[ylab].dims[0], darray[xlab].dims[0])

    # May need to transpose for correct x, y labels
    # xlab may be the name of a coord, we have to check for dim names
    if imshow_rgb:
        # For RGB[A] images, matplotlib requires the color dimension
        # to be last.  In Xarray the order should be unimportant, so
        # we transpose to (y, x, color) to make this work.
        yx_dims = (ylab, xlab)
        dims = yx_dims + tuple(d for d in darray.dims if d not in yx_dims)

    if dims != darray.dims:
        darray = darray.transpose(*dims, transpose_coords=True)

    # Pass the data as a masked ndarray too
    zval = darray.to_masked_array(copy=False)

    # Replace pd.Intervals if contained in xval or yval.
    xplt, xlab_extra = _resolve_intervals_2dplot(xval, plotfunc.__name__)
    yplt, ylab_extra = _resolve_intervals_2dplot(yval, plotfunc.__name__)

    _ensure_plottable(xplt, yplt, zval)

    cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs(
        plotfunc, zval.data, **locals()
    )

    if "contour" in plotfunc.__name__:
        # extend is a keyword argument only for contour and contourf, but
        # passing it to the colorbar is sufficient for imshow and
        # pcolormesh
        kwargs["extend"] = cmap_params["extend"]
        kwargs["levels"] = cmap_params["levels"]
        # if colors == a single color, matplotlib draws dashed negative
        # contours. we lose this feature if we pass cmap and not colors
        if isinstance(colors, str):
            cmap_params["cmap"] = None
            kwargs["colors"] = colors

    if "pcolormesh" == plotfunc.__name__:
        kwargs["infer_intervals"] = infer_intervals

    if "imshow" == plotfunc.__name__ and isinstance(aspect, str):
        # forbid usage of mpl strings
        raise ValueError("plt.imshow's `aspect` kwarg is not available in xarray")

    ax = get_axis(figsize, size, aspect, ax)
    primitive = plotfunc(
        xplt,
        yplt,
        zval,
        ax=ax,
        cmap=cmap_params["cmap"],
        vmin=cmap_params["vmin"],
        vmax=cmap_params["vmax"],
        norm=cmap_params["norm"],
        **kwargs,
    )

    # Label the plot with metadata
    if add_labels:
        ax.set_xlabel(label_from_attrs(darray[xlab], xlab_extra))
        ax.set_ylabel(label_from_attrs(darray[ylab], ylab_extra))
        ax.set_title(darray._title_for_slice())

    if add_colorbar:
        if add_labels and "label" not in cbar_kwargs:
            cbar_kwargs["label"] = label_from_attrs(darray)
        cbar = _add_colorbar(primitive, ax, cbar_ax, cbar_kwargs, cmap_params)
    elif cbar_ax is not None or cbar_kwargs:
        # inform the user about keywords which aren't used
        raise ValueError(
            "cbar_ax and cbar_kwargs can't be used with add_colorbar=False."
        )

    # origin kwarg overrides yincrease
    if "origin" in kwargs:
        yincrease = None

    _update_axes(ax, xincrease, yincrease, xscale, yscale, xticks, yticks, xlim, ylim)

    # Rotate dates on xlabels
    # Do this without calling autofmt_xdate so that x-axes ticks
    # on other subplots (if any) are not deleted.
    # https://stackoverflow.com/questions/17430105/autofmt-xdate-deletes-x-axis-labels-of-all-subplots
    if np.issubdtype(xplt.dtype, np.datetime64):
        for xlabels in ax.get_xticklabels():
            xlabels.set_rotation(30)
            xlabels.set_ha("right")

    return primitive