Returns PGFPlots code for a number of patch objects.

def draw_patchcollection(data, obj):
    """Returns PGFPlots code for a number of patch objects.
    """
    content = []
    # Gather the draw options.
    try:
        ec = obj.get_edgecolor()[0]
    except IndexError:
        ec = None

    try:
        fc = obj.get_facecolor()[0]
    except IndexError:
        fc = None

    try:
        ls = obj.get_linestyle()[0]
    except IndexError:
        ls = None

    try:
        w = obj.get_linewidth()[0]
    except IndexError:
        w = None

    data, draw_options = mypath.get_draw_options(data, obj, ec, fc, ls, w)

    paths = obj.get_paths()
    for path in paths:
        data, cont, draw_options, is_area = mypath.draw_path(
            data, path, draw_options=draw_options
        )
        content.append(cont)

    if _is_in_legend(obj):
        # Unfortunately, patch legend entries need \addlegendimage in Pgfplots.
        tpe = "area legend" if is_area else "line legend"
        do = ", ".join([tpe] + draw_options) if draw_options else ""
        content += [
            "\\addlegendimage{{{}}}\n".format(do),
            "\\addlegendentry{{{}}}\n\n".format(obj.get_label()),
        ]
    else:
        content.append("\n")

    return data, content