def create_contours_obj(canvas, contour_groups, colors=None, **kwargs):
    """Create and return a compound object for ginga `canvas`, consisting
    of a number of contour polygons.  `contour_groups` is a list of
    numpy arrays of points representing polygons, such as returned by
    calc_contours() or get_contours().
    `colors` (if provided) is a list of colors for each polygon.
    Any other keyword parameters are passed on to the Polygon class.
    """
    if colors is None:
        colors = ['black']
    Polygon = canvas.get_draw_class('polygon')
    Compound = canvas.get_draw_class('compoundobject')
    objs = [Polygon(contour, color=colors[i % len(colors)], **kwargs)
            for i, contours in enumerate(contour_groups)
            for n, contour in enumerate(contours)
            ]
    contours_obj = Compound(*objs)
    return contours_obj