import matplotlib.transforms
class InsetPosition(object):
def __init__(self, parent, lbwh):
self.parent = parent
self.lbwh = lbwh # position of the inset axes in the
normalized coordinate of the parent axes
def __call__(self, ax, renderer):
bbox_parent = self.parent.get_position(original=False)
trans = matplotlib.transforms.BboxTransformTo(bbox_parent)
bbox_inset = matplotlib.transforms.Bbox.from_bounds(*self.lbwh)
bb = matplotlib.transforms.TransformedBbox(bbox_inset, trans)
return bb
ax = gca()
ax.set_aspect(1.)
axins = axes([0, 0, 1, 1])
ip = InsetPosition(ax, [0.5, 0.1, 0.4, 0.2])
axins.set_axes_locator(ip)
TODO:
- anchor to the parent axes
- adjust the inset size according to its data limits
No comments:
Post a Comment