def _draw_rectangle(data, obj, draw_options):
    """Return the PGFPlots code for rectangles.
    """
    label = obj.get_label()
    if label == '':
        return data, []
    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
