Fig = plt.figure()
ax = plt.subplot(111)
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
ax.plot(t, s1, 'b-', label='dots')
leg = ax.legend()
leg.set_zorder(1)
plt.draw()
bbox = leg.legendPatch.get_bbox().inverse_transformed(ax.transAxes)
rectangle = Rectangle((bbox.x0, bbox.y0), bbox.width * 0.8, bbox.height * 
    0.8, fc='red', transform=ax.transAxes, zorder=2)
ax.add_patch(rectangle)
plt.show()
How do I draw a rectangle on the legend in matplotlib?