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

Commitff77c7f

Browse files
committed
Cleanups to Annotation.
- Reorder logic in _get_xy_transform to make the case of xy0 not being specified (i.e. invalid bbox_name) fail more obviously.- Document "offset fontsize" option.
1 parentffd3b12 commitff77c7f

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

‎lib/matplotlib/text.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,13 +1478,13 @@ def _get_xy_transform(self, renderer, coords):
14781478
trans=tr+self.axes.transData
14791479
returntrans
14801480

1481-
s_=coords.split()
1482-
iflen(s_)!=2:
1483-
raiseValueError(f"{coords!r} is not a valid coordinate")
1481+
try:
1482+
bbox_name,unit=coords.split()
1483+
exceptValueError:# i.e. len(coords.split()) != 2.
1484+
raiseValueError(f"{coords!r} is not a valid coordinate")fromNone
14841485

14851486
bbox0,xy0=None,None
14861487

1487-
bbox_name,unit=s_
14881488
# if unit is offset-like
14891489
ifbbox_name=="figure":
14901490
bbox0=self.figure.figbbox
@@ -1493,35 +1493,27 @@ def _get_xy_transform(self, renderer, coords):
14931493
elifbbox_name=="axes":
14941494
bbox0=self.axes.bbox
14951495

1496+
# reference x, y in display coordinate
14961497
ifbbox0isnotNone:
14971498
xy0=bbox0.p0
14981499
elifbbox_name=="offset":
14991500
xy0=self._get_position_xy(renderer)
1500-
1501-
ifxy0isnotNone:
1502-
# reference x, y in display coordinate
1503-
ref_x,ref_y=xy0
1504-
ifunit=="points":
1505-
# dots per points
1506-
dpp=self.figure.dpi/72
1507-
tr=Affine2D().scale(dpp)
1508-
elifunit=="pixels":
1509-
tr=Affine2D()
1510-
elifunit=="fontsize":
1511-
fontsize=self.get_size()
1512-
dpp=fontsize*self.figure.dpi/72
1513-
tr=Affine2D().scale(dpp)
1514-
elifunit=="fraction":
1515-
w,h=bbox0.size
1516-
tr=Affine2D().scale(w,h)
1517-
else:
1518-
raiseValueError(f"{unit!r} is not a recognized unit")
1519-
1520-
returntr.translate(ref_x,ref_y)
1521-
15221501
else:
15231502
raiseValueError(f"{coords!r} is not a valid coordinate")
15241503

1504+
ifunit=="points":
1505+
tr=Affine2D().scale(self.figure.dpi/72)# dpi/72 dots per point
1506+
elifunit=="pixels":
1507+
tr=Affine2D()
1508+
elifunit=="fontsize":
1509+
tr=Affine2D().scale(self.get_size()*self.figure.dpi/72)
1510+
elifunit=="fraction":
1511+
tr=Affine2D().scale(*bbox0.size)
1512+
else:
1513+
raiseValueError(f"{unit!r} is not a recognized unit")
1514+
1515+
returntr.translate(*xy0)
1516+
15251517
defset_annotation_clip(self,b):
15261518
"""
15271519
Set the annotation's clipping behavior.
@@ -1701,15 +1693,15 @@ def transform(renderer) -> Transform
17011693
or callable, default: value of *xycoords*
17021694
The coordinate system that *xytext* is given in.
17031695
1704-
All *xycoords* values are valid as well as the following
1705-
strings:
1696+
All *xycoords* values are valid as well as the following strings:
17061697
1707-
================= =========================================
1698+
================= =================================================
17081699
Value Description
1709-
================= =========================================
1710-
'offset points' Offset (in points) from the *xy* value
1711-
'offset pixels' Offset (in pixels) from the *xy* value
1712-
================= =========================================
1700+
================= =================================================
1701+
'offset points' Offset, in points, from the *xy* value
1702+
'offset pixels' Offset, in pixels, from the *xy* value
1703+
'offset fontsize' Offset, relative to fontsize, from the *xy* value
1704+
================= =================================================
17131705
17141706
arrowprops : dict, optional
17151707
The properties used to draw a `.FancyArrowPatch` arrow between the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp