Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit745c737

Browse files
committed
Add InsetIndicator artist
Behaviour changes at this point* return type for indicate_inset[_zoom]* the connectors do not exist until draw because their position requires knowledge of the axes they are added to* since get_window_extent/get_tightbbox is not yet implemented, this will likely not interact well with layout engines (though it already didn't - see#23425)
1 parent109ab93 commit745c737

File tree

10 files changed

+427
-77
lines changed

10 files changed

+427
-77
lines changed

‎doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Alphabetical list of modules:
106106
gridspec_api.rst
107107
hatch_api.rst
108108
image_api.rst
109+
inset_api.rst
109110
layout_engine_api.rst
110111
legend_api.rst
111112
legend_handler_api.rst

‎doc/api/inset_api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
********************
2+
``matplotlib.inset``
3+
********************
4+
5+
..automodule::matplotlib.inset
6+
:members:
7+
:undoc-members:
8+
:show-inheritance:

‎lib/matplotlib/axes/_axes.py

Lines changed: 31 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
importmatplotlib.contourasmcontour
1717
importmatplotlib.dates# noqa: F401, Register date unit converter as side effect.
1818
importmatplotlib.imageasmimage
19+
importmatplotlib.insetasminset
1920
importmatplotlib.legendasmlegend
2021
importmatplotlib.linesasmlines
2122
importmatplotlib.markersasmmarkers
@@ -418,7 +419,7 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
418419
returninset_ax
419420

420421
@_docstring.dedent_interpd
421-
defindicate_inset(self,bounds,inset_ax=None,*,transform=None,
422+
defindicate_inset(self,bounds=None,inset_ax=None,*,transform=None,
422423
facecolor='none',edgecolor='0.5',alpha=0.5,
423424
zorder=4.99,**kwargs):
424425
"""
@@ -432,11 +433,12 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
432433
433434
Parameters
434435
----------
435-
bounds : [x0, y0, width, height]
436+
bounds : [x0, y0, width, height], optional
436437
Lower-left corner of rectangle to be marked, and its width
437-
and height.
438+
and height. If not set, the bounds will be calculated from the
439+
data limits of inset_ax, which must be supplied.
438440
439-
inset_ax : `.Axes`
441+
inset_ax : `.Axes`, optional
440442
An optional inset Axes to draw connecting lines to. Two lines are
441443
drawn connecting the indicator box to the inset Axes on corners
442444
chosen so as to not overlap with the indicator box.
@@ -466,14 +468,16 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
466468
467469
Returns
468470
-------
469-
rectangle_patch : `.patches.Rectangle`
470-
The indicator frame.
471+
inset_indicator : `.inset.InsetIndicator` artist containing
472+
473+
inset_indicator.rectangle : `.Rectangle`
474+
The indicator frame.
471475
472-
connector_lines : 4-tuple of `.patches.ConnectionPatch`
473-
The four connector lines connecting to (lower_left, upper_left,
474-
lower_right upper_right) corners of *inset_ax*. Two lines are
475-
set with visibility to *False*, but the user can set the
476-
visibility to True if the automatic choice is not deemed correct.
476+
inset_indicator.connectors : 4-tuple of `.patches.ConnectionPatch`
477+
The four connector lines connecting to (lower_left, upper_left,
478+
lower_right upper_right) corners of *inset_ax*. Two lines are
479+
set with visibility to *False*, but the user can set the
480+
visibility to True if the automatic choice is not deemed correct.
477481
478482
"""
479483
# to make the Axes connectors work, we need to apply the aspect to
@@ -484,51 +488,13 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
484488
transform=self.transData
485489
kwargs.setdefault('label','_indicate_inset')
486490

487-
x,y,width,height=bounds
488-
rectangle_patch=mpatches.Rectangle(
489-
(x,y),width,height,
491+
indicator_patch=minset.InsetIndicator(
492+
bounds,inset_ax=inset_ax,
490493
facecolor=facecolor,edgecolor=edgecolor,alpha=alpha,
491494
zorder=zorder,transform=transform,**kwargs)
492-
self.add_patch(rectangle_patch)
493-
494-
connects= []
495-
496-
ifinset_axisnotNone:
497-
# connect the inset_axes to the rectangle
498-
forxy_inset_axin [(0,0), (0,1), (1,0), (1,1)]:
499-
# inset_ax positions are in axes coordinates
500-
# The 0, 1 values define the four edges if the inset_ax
501-
# lower_left, upper_left, lower_right upper_right.
502-
ex,ey=xy_inset_ax
503-
ifself.xaxis.get_inverted():
504-
ex=1-ex
505-
ifself.yaxis.get_inverted():
506-
ey=1-ey
507-
xy_data=x+ex*width,y+ey*height
508-
p=mpatches.ConnectionPatch(
509-
xyA=xy_inset_ax,coordsA=inset_ax.transAxes,
510-
xyB=xy_data,coordsB=self.transData,
511-
arrowstyle="-",zorder=zorder,
512-
edgecolor=edgecolor,alpha=alpha)
513-
connects.append(p)
514-
self.add_patch(p)
515-
516-
# decide which two of the lines to keep visible....
517-
pos=inset_ax.get_position()
518-
bboxins=pos.transformed(self.figure.transSubfigure)
519-
rectbbox=mtransforms.Bbox.from_bounds(
520-
*bounds
521-
).transformed(transform)
522-
x0=rectbbox.x0<bboxins.x0
523-
x1=rectbbox.x1<bboxins.x1
524-
y0=rectbbox.y0<bboxins.y0
525-
y1=rectbbox.y1<bboxins.y1
526-
connects[0].set_visible(x0^y0)
527-
connects[1].set_visible(x0==y1)
528-
connects[2].set_visible(x1==y0)
529-
connects[3].set_visible(x1^y1)
530-
531-
returnrectangle_patch,tuple(connects)ifconnectselseNone
495+
self.add_artist(indicator_patch)
496+
497+
returnindicator_patch
532498

533499
defindicate_inset_zoom(self,inset_ax,**kwargs):
534500
"""
@@ -552,22 +518,19 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
552518
553519
Returns
554520
-------
555-
rectangle_patch : `.patches.Rectangle`
556-
Rectangle artist.
557-
558-
connector_lines : 4-tuple of `.patches.ConnectionPatch`
559-
Each of four connector lines coming from the rectangle drawn on
560-
this axis, in the order lower left, upper left, lower right,
561-
upper right.
562-
Two are set with visibility to *False*, but the user can
563-
setthe visibility to *True* iftheautomatic choice is not deemed
564-
correct.
521+
inset_indicator : `.inset.InsetIndicator` artist containing
522+
523+
inset_indicator.rectangle : `.Rectangle`
524+
The indicator frame.
525+
526+
inset_indicator.connectors : 4-tuple of `.patches.ConnectionPatch`
527+
The four connector lines connecting to (lower_left, upper_left,
528+
lower_right upper_right) corners of *inset_ax*. Two lines are
529+
setwith visibility to *False*, buttheuser can set the
530+
visibility to True if the automatic choice is not deemedcorrect.
565531
"""
566532

567-
xlim=inset_ax.get_xlim()
568-
ylim=inset_ax.get_ylim()
569-
rect= (xlim[0],ylim[0],xlim[1]-xlim[0],ylim[1]-ylim[0])
570-
returnself.indicate_inset(rect,inset_ax,**kwargs)
533+
returnself.indicate_inset(None,inset_ax,**kwargs)
571534

572535
@_docstring.dedent_interpd
573536
defsecondary_xaxis(self,location,functions=None,*,transform=None,**kwargs):

‎lib/matplotlib/axes/_axes.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ from matplotlib.colors import Colormap, Normalize
1515
frommatplotlib.containerimportBarContainer,ErrorbarContainer,StemContainer
1616
frommatplotlib.contourimportContourSet,QuadContourSet
1717
frommatplotlib.imageimportAxesImage,PcolorImage
18+
frommatplotlib.insetimportInsetIndicator
1819
frommatplotlib.legendimportLegend
1920
frommatplotlib.legend_handlerimportHandlerBase
2021
frommatplotlib.linesimportLine2D,AxLine
@@ -83,8 +84,8 @@ class Axes(_AxesBase):
8384
alpha:float= ...,
8485
zorder:float= ...,
8586
**kwargs
86-
)->Rectangle: ...
87-
defindicate_inset_zoom(self,inset_ax:Axes,**kwargs)->Rectangle: ...
87+
)->InsetIndicator: ...
88+
defindicate_inset_zoom(self,inset_ax:Axes,**kwargs)->InsetIndicator: ...
8889
defsecondary_xaxis(
8990
self,
9091
location:Literal["top","bottom"]|float,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp