def add_offsetboxes(ax, size=10, margin=0.1, color=u'black'):
 (m, mp) = (margin, (1 + margin))
 anchor_points = [((- m), (- m)), ((- m), 0.5), ((- m), mp), (mp, 0.5), (0.5, mp), (mp, mp), (0.5, (- m)), (mp, (- m)), (0.5, (- m))]
 for point in anchor_points:
  da = DrawingArea(size, size)
  background = Rectangle((0, 0), width=size, height=size, facecolor=color, edgecolor=u'None', linewidth=0, antialiased=False)
  da.add_artist(background)
  anchored_box = AnchoredOffsetbox(loc=10, child=da, pad=0.0, frameon=False, bbox_to_anchor=point, bbox_transform=ax.transAxes, borderpad=0.0)
  ax.add_artist(anchored_box)
 return anchored_box

def add_offsetboxes ( ax , size = 10 , margin = 0.1 , color = u'black' ) : ( m , mp ) = ( margin , ( 1 + margin ) ) anchor_points = [ ( ( - m ) , ( - m ) ) , ( ( - m ) , 0.5 ) , ( ( - m ) , mp ) , ( mp , 0.5 ) , ( 0.5 , mp ) , ( mp , mp ) , ( 0.5 , ( - m ) ) , ( mp , ( - m ) ) , ( 0.5 , ( - m ) ) ] for point in anchor_points : da = DrawingArea ( size , size ) background = Rectangle ( ( 0 , 0 ) , width = size , height = size , facecolor = color , edgecolor = u'None' , linewidth = 0 , antialiased = False ) da . add_artist ( background ) anchored_box = AnchoredOffsetbox ( loc = 10 , child = da , pad = 0.0 , frameon = False , bbox_to_anchor = point , bbox_transform = ax . transAxes , borderpad = 0.0 ) ax . add_artist ( anchored_box ) return anchored_box
surround ax with offsetboxes .