def draw_from_point_to_point(parent_axes, insert_axes, point1, point2, **kwargs): from mpl_toolkits.axes_grid1.inset_locator import TransformedBbox, BboxConnector, Bbox rect = TransformedBbox(Bbox([point1, point1]), parent_axes.transData) rect2 = TransformedBbox(Bbox([point2, point2]), insert_axes.transData) # rect = TransformedBbox(Bbox([[1, 0], [1, 0]]), parent_axes.transData) loc = 1 p1 = BboxConnector(rect, rect2, loc, **kwargs) parent_axes.add_patch(p1) p1.set_clip_on(False) return p1
def mark_inset(parent_axes, inset_axes, loc1a=1, loc1b=1, loc2a=2, loc2b=2, **kwargs): rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData) pp = BboxPatch(rect, fill=False, linewidth=.5, **kwargs) parent_axes.add_patch(pp) p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1a, loc2=loc1b, linewidth=.5, **kwargs) inset_axes.add_patch(p1) p1.set_clip_on(False) p2 = BboxConnector(inset_axes.bbox, rect, loc1=loc2a, loc2=loc2b, linewidth=.5, **kwargs) inset_axes.add_patch(p2) p2.set_clip_on(False) return pp, p1, p2
def mark_inset(ax, ax2, m, m2, MAP, loc1=(1, 2), loc2=(3, 4), **kwargs): """ https://stackoverflow.com/questions/41610834/basemap-projection-geos-controlling-mark-inset-location Patched mark_inset to work with Basemap. Reason: Basemap converts Geographic (lon/lat) to Map Projection (x/y) coordinates Additionally: set connector locations separately for both axes: loc1 & loc2: tuple defining start and end-locations of connector 1 & 2 """ axzoom_geoLims = (MAP['cyl'][2:], MAP['cyl'][:2]) rect = TransformedBbox(Bbox(np.array(m(*axzoom_geoLims)).T), ax.transData) pp = BboxPatch(rect, fill=False, **kwargs) ax.add_patch(pp) p1 = BboxConnector(ax2.bbox, rect, loc1=loc1[0], loc2=loc1[1], **kwargs) ax2.add_patch(p1) p1.set_clip_on(False) p2 = BboxConnector(ax2.bbox, rect, loc1=loc2[0], loc2=loc2[1], **kwargs) ax2.add_patch(p2) p2.set_clip_on(False) return pp, p1, p2
def mark_inset(parent_axes, inset_axes, loc1=1, loc2=2, **kwargs): from mpl_toolkits.axes_grid1.inset_locator import TransformedBbox, BboxPatch, BboxConnector try: loc1a, loc1b = loc1 except: loc1a = loc1 loc1b = loc1 try: loc2a, loc2b = loc2 except: loc2a = loc2 loc2b = loc2 rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData) pp = BboxPatch(rect, fill=False, **kwargs) parent_axes.add_patch(pp) pp.set_clip_on(False) p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1a, loc2=loc1b, **kwargs) inset_axes.add_patch(p1) p1.set_clip_on(False) p2 = BboxConnector(inset_axes.bbox, rect, loc1=loc2a, loc2=loc2b, **kwargs) inset_axes.add_patch(p2) p2.set_clip_on(False) return pp, p1, p2
def mark_geo_inset(ax, ax2, m, m2, loc1=(1, 2), loc2=(3, 4), **kwargs): """ Patched mark_inset to work with Basemap. Reason: Basemap converts Geographic (lon/lat) to Map Projection (x/y) coordinates See: https://stackoverflow.com/questions/41610834/basemap-projection-geos-controlling-mark-inset-location Args: ax (subplot): parent subplot where inset is marked on parent map ax2 (subplot): inset subplot where inset map is displayed m (basemap): parent basemap associated with ax m2 (basemap): inset basemap associated with ax2 loc1 (tuple): start and end locations of connector 1 loc2 (tuple): start and end locations of connector 2 **kwargs (optional args): to manage the presentation of the connectors and inset markers loc tuple values: 'upper right' : 1, 'upper left' : 2, 'lower left' : 3, 'lower right' : 4 Returns: BboxPatch: Patch for the inset coverage on the parent subplot BboxConnector: Connector line 1 connecting the coverage rectangle on the parent subplot to the inset map BboxConnector: Connector line 2 connecting the coverage rectanlge on the parent subplot to the inset map """ # Doesn't work for Basemap # rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData) # axzoom_geoLims = np.array(m2(*ax2.viewLim._points.T, inverse=True)) axzoom_geoLims = m2(ax2.get_xlim(), ax2.get_ylim(), inverse=True) rect = TransformedBbox(Bbox(np.array(m(*axzoom_geoLims)).T), ax.transData) pp = BboxPatch(rect, fill=False, **kwargs) ax.add_patch(pp) p1 = BboxConnector(ax2.bbox, rect, loc1=loc1[0], loc2=loc1[1], **kwargs) ax2.add_patch(p1) p1.set_clip_on(False) p2 = BboxConnector(ax2.bbox, rect, loc1=loc2[0], loc2=loc2[1], **kwargs) ax2.add_patch(p2) p2.set_clip_on(False) return pp, p1, p2
def _mark_inset(parent_axes, inset_axes, loc1a = 1, loc1b = 1, loc2a = 2, loc2b = 2, **kwargs): # Draw a bbox of the region of the inset axes in the parent axes and # connecting lines between the bbox and the inset axes area # loc1, loc2 : {1, 2, 3, 4} rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData) pp = BboxPatch(rect, fill = False, **kwargs) parent_axes.add_patch(pp) p1 = BboxConnector(inset_axes.bbox, rect, loc1 = loc1a, loc2 = loc1b, **kwargs) inset_axes.add_patch(p1) p1.set_clip_on(False) p2 = BboxConnector(inset_axes.bbox, rect, loc1 = loc2a, loc2 = loc2b, **kwargs) inset_axes.add_patch(p2) p2.set_clip_on(False) print('\nInset created') return pp, p1, p2
def mark_inset(parent_axes, inset_axes, loc1a=1, loc1b=1, loc2a=2, loc2b=2, **kwargs): """ Redefined the mark_inset function. Gives freedom to connect any corner of an inset plot to any corner of the parent plot. """ rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData) pp = BboxPatch(rect, fill=False, **kwargs) parent_axes.add_patch(pp) p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1a, loc2=loc1b, **kwargs) inset_axes.add_patch(p1) p1.set_clip_on(False) p2 = BboxConnector(inset_axes.bbox, rect, loc1=loc2a, loc2=loc2b, **kwargs) inset_axes.add_patch(p2) p2.set_clip_on(False) return pp, p1, p2
def mark_inset(parent_axes, inset_axes, loc1a=1, loc1b=1, loc2a=2, loc2b=2, **kwargs): # Draw a bbox of the region of the inset axes in the parent axes and # connecting lines between the bbox and the inset axes area # loc1, loc2 : {1, 2, 3, 4} from mpl_toolkits.axes_grid1.inset_locator import TransformedBbox, BboxPatch, BboxConnector rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData) pp = BboxPatch(rect, fill=False, **kwargs) parent_axes.add_patch(pp) p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1a, loc2=loc1b, **kwargs) inset_axes.add_patch(p1) p1.set_clip_on(False) p2 = BboxConnector(inset_axes.bbox, rect, loc1=loc2a, loc2=loc2b, **kwargs) inset_axes.add_patch(p2) p2.set_clip_on(False) return pp, p1, p2
mark_inset(parent_axes=parent_ax, inset_axes=axins, loc1=ZR['l1'], loc2=ZR['l2'], fc="none", ec="0.5") else: # if 'fitsfile' in ZR blt = bl.transform_to(parent_ax.wcs.wcs.radesys.lower()) trt = tr.transform_to(parent_ax.wcs.wcs.radesys.lower()) (rx1, ry1), (rx2, ry2) = (parent_ax.wcs.wcs_world2pix( [[blt.ra.deg, blt.dec.deg]], 0)[0], parent_ax.wcs.wcs_world2pix( [[trt.ra.deg, trt.dec.deg]], 0)[0]) bbox = Bbox(np.array([(rx1, ry1), (rx2, ry2)])) rect = TransformedBbox(bbox, parent_ax.transData) markinkwargs = dict(fc='none', ec='0.5') pp = BboxPatch(rect, fill=False, **markinkwargs) parent_ax.add_patch(pp) p1 = BboxConnector(axins.bbox, rect, loc1=ZR['l1'], **markinkwargs) axins.add_patch(p1) p1.set_clip_on(False) p2 = BboxConnector(axins.bbox, rect, loc1=ZR['l2'],