Return the PGFPlots code for rectangles.

def _draw_rectangle(data, obj, draw_options):
    """Return the PGFPlots code for rectangles.
    """
    # Objects with labels are plot objects (from bar charts, etc).  Even those without
    # labels explicitly set have a label of "_nolegend_".  Everything else should be
    # skipped because they likely correspong to axis/legend objects which are handled by
    # PGFPlots
    label = obj.get_label()
    if label == "":
        return data, []

    # Get actual label, bar charts by default only give rectangles labels of
    # "_nolegend_". See <https://stackoverflow.com/q/35881290/353337>.
    handles, labels = obj.axes.get_legend_handles_labels()
    labelsFound = [
        label for h, label in zip(handles, labels) if obj in h.get_children()
    ]
    if len(labelsFound) == 1:
        label = labelsFound[0]

    left_lower_x = obj.get_x()
    left_lower_y = obj.get_y()
    ff = data["float format"]
    cont = (
        "\\draw[{}] (axis cs:" + ff + "," + ff + ") "
        "rectangle (axis cs:" + ff + "," + ff + ");\n"
    ).format(
        ",".join(draw_options),
        left_lower_x,
        left_lower_y,
        left_lower_x + obj.get_width(),
        left_lower_y + obj.get_height(),
    )

    if label != "_nolegend_" and label not in data["rectangle_legends"]:
        data["rectangle_legends"].add(label)
        cont += "\\addlegendimage{{ybar,ybar legend,{}}};\n".format(
            ",".join(draw_options)
        )
        cont += "\\addlegendentry{{{}}}\n\n".format(label)
    return data, cont