@@ -405,7 +405,7 @@ def _remove_legend(self, legend):
405
405
406
406
def inset_axes (self , rect , transform = None , ** kwargs ):
407
407
"""
408
- Add a child axes to the existing axes.
408
+ Add a child inset axes to this existing axes.
409
409
410
410
Parameters
411
411
----------
@@ -417,6 +417,10 @@ def inset_axes(self, rect, transform=None, **kwargs):
417
417
Defaults to `ax.transAxes`, i.e. the units of *rect* are in
418
418
axes-relative coordinates.
419
419
420
+ zorder : number
421
+ Defaults to 5 (same as `.Axes.legend`). Adjust higher or lower
422
+ to change whether it is above or below data plotted on the axes.
423
+
420
424
Other Parameters
421
425
----------------
422
426
@@ -447,64 +451,91 @@ def inset_axes(self, rect, transform=None, **kwargs):
447
451
bb = _inset_locator (rect , transform , self )(None , None )
448
452
# if not set, set to the same zorder as legend
449
453
zorder = kwargs .pop ('zorder' , 5 )
450
- axins = Axes (self .figure , bb .bounds , zorder = zorder ,
454
+ inset_ax = Axes (self .figure , bb .bounds , zorder = zorder ,
451
455
label = label , ** kwargs )
452
456
453
457
# this locator lets the axes move if in data coordinates.
454
458
# it gets called in `ax.apply_aspect() (of all places)
455
459
axes_locator = _inset_locator (rect , transform , self )
456
- axins .set_axes_locator (axes_locator )
460
+ inset_ax .set_axes_locator (axes_locator )
457
461
458
- self .add_child_axes (axins )
462
+ self .add_child_axes (inset_ax )
459
463
460
- return axins
464
+ return inset_ax
461
465
462
- def inset_indicator (self , rect , axins = None , transform = None ,
466
+ def inset_rectangle (self , rect , inset_ax = None , transform = None ,
463
467
facecolor = 'none' , edgecolor = '0.5' , alpha = 0.5 ,
464
468
zorder = 4.99 , ** kwargs ):
465
469
"""
466
- Add an inset indicator to the axes. This is a box on the plot that
467
- can optionally have lines joining it to an inset axes *axins*.
470
+ Add an inset indicator to the axes. This is a rectangle on the plot
471
+ at the position indicated by *rect* that optionally has lines that
472
+ connect the rectangle to an inset axes (`.Axes.inset_axes`).
468
473
469
474
Parameters
470
475
----------
471
476
472
477
rect : [x0, y0, width, height]
473
- Lower-left corner of area to be marked, and its width and height.
478
+ Lower-left corner of rectangle to be marked, and its width
479
+ and height.
474
480
475
- axins : `Axes`
476
- An optional axes to join this indicator to. Two lines are drawn
477
- connecting the indicator box to the inset axes on corners chosen
478
- so as to not overlap with the indicator box.
481
+ inset_ax : `. Axes`
482
+ An optional inset axes to draw connecting lines to. Two lines are
483
+ drawn connecting the indicator box to the inset axes on corners
484
+ chosen so as to not overlap with the indicator box.
479
485
480
486
transform : `.Transform`
481
- Defaults to `ax.transAxes`, i.e. the units of *rect* are in
482
- axes-relative coordinates.
487
+ Transform for the rectangle co-ordinates. Defaults to
488
+ `ax.transAxes`, i.e. the units of *rect* are in axes-relative
489
+ coordinates.
490
+
491
+ facecolor : Matplotlib color
492
+ Facecolor of the rectangle (default 'none')
493
+
494
+ edgecolor : Matplotlib color
495
+ Color of the rectangle and color of the connecting lines. Default
496
+ is '0.5'
497
+
498
+ alpha : number
499
+ Transparency of the rectangle and connector lines. Default 0.5
500
+
501
+ zorder : number
502
+ drawing order of the rectangle and connector lines. Default 4.99
503
+ (just below the default level of inset axes)
483
504
484
505
Other Parameters
485
506
----------------
486
507
487
- kwargs are passed on to the `axes.Axes` child axes .
508
+ Other * kwargs* are passed on to the rectangle patch .
488
509
489
510
Returns
490
511
-------
491
512
492
- ??
513
+ rectangle_patch, connector_lines :
514
+ `.Patches.Rectagle`, (four-tupple `.Patches.ConnectionPatch`) one
515
+ for each of four connector lines. Two are set with visibility to
516
+ *False*, but the user can set the visibility to True if the
517
+ automatic choice is not deemed correct.
493
518
494
519
"""
520
+
521
+ # to make the axes connectors work, we need to apply the aspect to
522
+ # the parent axes.
523
+ self .apply_aspect ()
524
+
495
525
if transform is None :
496
526
transform = self .transData
497
527
label = kwargs .pop ('label' , 'inset_indicator' )
528
+
498
529
xy = (rect [0 ], rect [1 ])
499
530
rectpatch = mpatches .Rectangle (xy , rect [2 ], rect [3 ],
500
531
facecolor = facecolor , edgecolor = edgecolor , alpha = alpha ,
501
532
zorder = zorder , label = label , transform = transform , ** kwargs )
502
533
self .add_patch (rectpatch )
503
534
504
- if not axins is None :
535
+ if not inset_ax is None :
505
536
# want to connect the indicator to the rect....
506
537
507
- pos = axins .get_position () # this is in fig-fraction.
538
+ pos = inset_ax .get_position () # this is in fig-fraction.
508
539
coordsA = 'axes fraction'
509
540
connects = []
510
541
xr = [rect [0 ], rect [0 ]+ rect [2 ]]
@@ -515,11 +546,12 @@ def inset_indicator(self, rect, axins=None, transform=None,
515
546
xyB = (xr [xc ], yr [yc ])
516
547
connects += [mpatches .ConnectionPatch (xyA , xyB ,
517
548
'axes fraction' , 'data' ,
518
- axesA = axins , axesB = self , arrowstyle = "-" ,
549
+ axesA = inset_ax , axesB = self , arrowstyle = "-" ,
519
550
zorder = zorder , edgecolor = edgecolor , alpha = alpha )]
520
551
self .add_patch (connects [- 1 ])
521
552
# decide which two of the lines to keep visible....
522
- bboxins = axins .get_position ().transformed (self .figure .transFigure )
553
+ pos = inset_ax .get_position ()
554
+ bboxins = pos .transformed (self .figure .transFigure )
523
555
rectbbox = mtransforms .Bbox .from_bounds (rect [0 ], rect [1 ],
524
556
rect [2 ], rect [3 ]).transformed (transform )
525
557
if rectbbox .x0 < bboxins .x0 :
@@ -533,10 +565,44 @@ def inset_indicator(self, rect, axins=None, transform=None,
533
565
connects [1 ].set_visible (False )
534
566
connects [2 ].set_visible (False )
535
567
536
- return rectpatch , connects
568
+ return rectpatch , connects
569
+
570
+ def zoom_inset_rectangle (self , inset_ax , ** kwargs ):
571
+ """
572
+ Add an inset indicator rectangle to the axes based on the axis
573
+ limits for an *inset_ax* and draw connectors between *inset_ax*
574
+ and the rectangle.
575
+
576
+ Parameters
577
+ ----------
578
+
579
+ inset_ax : `.Axes`
580
+ Inset axes to draw connecting lines to. Two lines are
581
+ drawn connecting the indicator box to the inset axes on corners
582
+ chosen so as to not overlap with the indicator box.
583
+
584
+ Other Parameters
585
+ ----------------
537
586
587
+ Other *kwargs* are passed on to `.Axes.inset_rectangle`
588
+
589
+ Returns
590
+ -------
591
+
592
+ rectangle_patch, connector_lines :
593
+ `.Patches.Rectagle`, (four-tupple `.Patches.ConnectionPatch`) one
594
+ for each of four connector lines. Two are set with visibility to
595
+ *False*, but the user can set the visibility to True if the
596
+ automatic choice is not deemed correct.
597
+
598
+ """
538
599
600
+ xlim = inset_ax .get_xlim ()
601
+ ylim = inset_ax .get_ylim ()
602
+ rect = [xlim [0 ], ylim [0 ], xlim [1 ] - xlim [0 ], ylim [1 ] - ylim [0 ]]
603
+ rectpatch , connects = self .inset_rectangle (rect , inset_ax , ** kwargs )
539
604
605
+ return rectpatch , connects
540
606
541
607
def text (self , x , y , s , fontdict = None , withdash = False , ** kwargs ):
542
608
"""
0 commit comments