def _process(self, element, key=None):
        try:
            from matplotlib import pyplot as plt
        except ImportError:
            raise ImportError("contours operation requires matplotlib.")
        figure_handle = plt.figure()
        extent = element.range(0) + element.range(1)[::-1]
        if self.p.filled:
            contour_fn = plt.contourf
            contour_type = Polygons
        else:
            contour_fn = plt.contour
            contour_type = Contours
        if type(element) is Raster:
            data = [np.flipud(element.data)]
        elif isinstance(element, Raster):
            data = [element.data]
        
        elif isinstance(element, QuadMesh):
            data = (element.dimension_values(0, False),
                    element.dimension_values(1, False),
                    element.data[2])
        contour_set = contour_fn(*data, extent=extent,
                                 levels=self.p.levels)

        contours = NdOverlay(None, kdims=['Levels'])
        for level, cset in zip(self.p.levels, contour_set.collections):
            paths = []
            for path in cset.get_paths():
                paths.extend(np.split(path.vertices, np.where(path.codes==1)[0][1:]))
            contours[level] = contour_type(paths, level=level, group=self.p.group,
                                           label=element.label, kdims=element.kdims,
                                           vdims=element.vdims)

        plt.close(figure_handle)
        if self.p.overlaid:
            contours = element * contours
        return contours
dataset/ETHPy150Open ioam/holoviews/holoviews/operation/element.py/contours._process/original