8000 Merge pull request #14652 from anntzer/transform_point · matplotlib/matplotlib@ace52ff · GitHub
[go: up one dir, main page]

Skip to content

Commit ace52ff

Browse files
authored
Merge pull request #14652 from anntzer/transform_point
Soft-deprecate transform_point.
2 parents 7976bad + 7b5ca17 commit ace52ff

26 files changed

+92
-117
lines changed

examples/misc/custom_projection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ def _set_lim_and_transforms(self):
174174

175175
def _get_affine_transform(self):
176176
transform = self._get_core_transform(1)
177-
xscale, _ = transform.transform_point((np.pi, 0))
178-
_, yscale = transform.transform_point((0, np.pi / 2.0))
177+
xscale, _ = transform.transform((np.pi, 0))
178+
_, yscale = transform.transform((0, np.pi/2))
179179
return Affine2D() \
180180
.scale(0.5 / xscale, 0.5 / yscale) \
181181
.translate(0.5, 0.5)

examples/pyplots/annotate_transform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ax.set_ylim(-1, 1)
2020

2121
xdata, ydata = 5, 0
22-
xdisplay, ydisplay = ax.transData.transform_point((xdata, ydata))
22+
xdisplay, ydisplay = ax.transData.transform((xdata, ydata))
2323

2424
bbox = dict(boxstyle="round", fc="0.8")
2525
arrowprops = dict(
@@ -52,6 +52,6 @@
5252
# in this example:
5353

5454
import matplotlib
55-
matplotlib.transforms.Transform.transform_point
55+
matplotlib.transforms.Transform.transform
5656
matplotlib.axes.Axes.annotate
5757
matplotlib.pyplot.annotate

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4046,8 +4046,7 @@ def _set_view_from_bbox(self, bbox, direction='in',
40464046

40474047
# zoom to rect
40484048
inverse = self.transData.inverted()
4049-
lastx, lasty = inverse.transform_point((lastx, lasty))
4050-
x, y = inverse.transform_point((x, y))
4049+
(lastx, lasty), (x, y) = inverse.transform([(lastx, lasty), (x, y)])
40514050

40524051
if twinx:
40534052
x0, x1 = Xmin, Xmax

lib/matplotlib/axis.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,8 @@ class Axis(martist.Artist):
737737
OFFSETTEXTPAD = 3
738738

739739
def __str__(self):
740-
return self.__class__.__name__ \
741-
+ "(%f,%f)" % tuple(self.axes.transAxes.transform_point((0, 0)))
740+
return "{}({},{})".format(
741+
type(self).__name__, *self.axes.transAxes.transform((0, 0)))
742742

743743
def __init__(self, axes, pickradius=15):
744744
"""
@@ -1929,11 +1929,10 @@ def contains(self, mouseevent):
19291929
x, y = mouseevent.x, mouseevent.y
19301930
try:
19311931
trans = self.axes.transAxes.inverted()
1932-
xaxes, yaxes = trans.transform_point((x, y))
1932+
xaxes, yaxes = trans.transform((x, y))
19331933
except ValueError:
19341934
return False, {}
1935-
l, b = self.axes.transAxes.transform_point((0, 0))
1936-
r, t = self.axes.transAxes.transform_point((1, 1))
1935+
(l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
19371936
inaxis = 0 <= xaxes <= 1 and (
19381937
b - self.pickradius < y < b or
19391938
t < y < t + self.pickradius)
@@ -2215,11 +2214,10 @@ def contains(self, mouseevent):
22152214
x, y = mouseevent.x, mouseevent.y
22162215
try:
22172216
trans = self.axes.transAxes.inverted()
2218-
xaxes, yaxes = trans.transform_point((x, y))
2217+
xaxes, yaxes = trans.transform((x, y))
22192218
except ValueError:
22202219
return False, {}
2221-
l, b = self.axes.transAxes.transform_point((0, 0))
2222-
r, t = self.axes.transAxes.transform_point((1, 1))
2220+
(l, b), (r, t) = self.axes.transAxes.transform([(0, 0), (1, 1)])
22232221
inaxis = 0 <= yaxes <= 1 and (
22242222
l - self.pickradius < x < l or
22252223
r < x < r + self.pickradius)

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ def _iter_collection(self, gc, master_transform, all_transforms,
415415
master_transform)
416416
else:
417417
transform = master_transform
418-
xo, yo = transform.transform_point((xo, yo))
419-
xp, yp = transform.transform_point((0, 0))
418+
(xo, yo), (xp, yp) = transform.transform(
419+
[(xo, yo), (0, 0)])
420420
xo = -(xp - xo)
421421
yo = -(yp - yo)
422422
if not (np.isfinite(xo) and np.isfinite(yo)):
@@ -1335,7 +1335,7 @@ def __init__(self, name, canvas, x, y, guiEvent=None):
13351335
if self.inaxes is not None:
13361336
try:
13371337
trans = self.inaxes.transData.inverted()
1338-
xdata, ydata = trans.transform_point((x, y))
1338+
xdata, ydata = trans.transform((x, y))
13391339
except ValueError:
13401340
pass
13411341
else:

lib/matplotlib/backends/backend_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
20592059
if elt[0] == 'font':
20602060
self.file.output(elt[1], elt[2], Op.selectfont)
20612061
elif elt[0] == 'text':
2062-
curx, cury = mytrans.transform_point((elt[1], elt[2]))
2062+
curx, cury = mytrans.transform((elt[1], elt[2]))
20632063
self._setup_textpos(curx, cury, angle, oldx, oldy)
20642064
oldx, oldy = curx, cury
20652065
if len(elt[3]) == 1:

lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
696696
# if text anchoring can be supported, get the original coordinates
697697
# and add alignment information
698698
pos = mtext.get_unitless_position()
699-
x, y = mtext.get_transform().transform_point(pos)
699+
x, y = mtext.get_transform().transform(pos)
700700
text_args.append("x=%fin" % (x * f))
701701
text_args.append("y=%fin" % (y * f))
702702

lib/matplotlib/backends/backend_svg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
10371037

10381038
# Get anchor coordinates.
10391039
transform = mtext.get_transform()
1040-
ax, ay = transform.transform_point(
1041-
mtext.get_unitless_position())
1040+
ax, ay = transform.transform(mtext.get_unitless_position())
10421041
ay = self.height - ay
10431042

10441043
# Don't do vertical anchor alignment. Most applications do not

lib/matplotlib/contour.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
402402
return rotation, nlc
403403

404404
def _get_label_text(self, x, y, rotation):
405-
dx, dy = self.ax.transData.inverted().transform_point((x, y))
405+
dx, dy = self.ax.transData.inverted().transform((x, y))
406406
t = text.Text(dx, dy, rotation=rotation,
407407
horizontalalignment='center',
408408
verticalalignment='center')
@@ -414,7 +414,7 @@ def _get_label_clabeltext(self, x, y, rotation):
414414
# class. This way, the rotation of the clabel is along the
415415
# contour line always.
416416
transDataInv = self.ax.transData.inverted()
417-
dx, dy = transDataInv.transform_point((x, y))
417+
dx, dy = transDataInv.transform((x, y))
418418
drotation = transDataInv.transform_angles(np.array([rotation]),
419419
np.array([[x, y]]))
420420
t = ClabelText(dx, dy, rotation=drotation[0],
@@ -480,7 +480,7 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
480480
transform = self.ax.transData
481481

482482
if transform:
483-
x, y = transform.transform_point((x, y))
483+
x, y = transform.transform((x, y))
484484

485485
# find the nearest contour _in screen units_
486486
conmin, segmin, imin, xmin, ymin = self.find_nearest_contour(
@@ -496,7 +496,7 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
496496
# grab its vertices
497497
lc = active_path.vertices
498498
# sort out where the new vertex should be added data-units
499-
xcmin = self.ax.transData.inverted().transform_point([xmin, ymin])
499+
xcmin = self.ax.transData.inverted().transform([xmin, ymin])
500500
# if there isn't a vertex close enough
501501
if not np.allclose(xcmin, lc[imin]):
502502
# insert new data into the vertex list

lib/matplotlib/image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,7 @@ def get_cursor_data(self, event):
906906
data_extent = Bbox([[ymin, xmin], [ymax, xmax]])
907907
array_extent = Bbox([[0, 0], arr.shape[:2]])
908908
trans = BboxTransform(boxin=data_extent, boxout=array_extent)
909-
y, x = event.ydata, event.xdata
910-
point = trans.transform_point([y, x])
909+
point = trans.transform([event.ydata, event.xdata])
911910
if any(np.isnan(point)):
912911
return None
913912
i, j = point.astype(int)

lib/matplotlib/legend.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,10 @@ def _update_loc(self, loc_in_canvas):
9393
bbox = self.legend.get_bbox_to_anchor()
9494

9595
_bbox_transform = BboxTransformFrom(bbox)
96-
self.legend._loc = tuple(
97-
_bbox_transform.transform_point(loc_in_canvas)
98-
)
96+
self.legend._loc = tuple(_bbox_transform.transform(loc_in_canvas))
9997

10098
def _update_bbox_to_anchor(self, loc_in_canvas):
101-
102-
tr = self.legend.axes.transAxes
103-
loc_in_bbox = tr.transform_point(loc_in_canvas)
104-
99+
loc_in_bbox = self.legend.axes.transAxes.transform(loc_in_canvas)
105100
self.legend.set_bbox_to_anchor(loc_in_bbox)
106101

107102

lib/matplotlib/patches.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ def theta_stretch(theta, scale):
15921592
theta2 = theta_stretch(self.theta2, width / height)
15931593

15941594
# Get width and height in pixels
1595-
width, height = self.get_transform().transform_point((width, height))
1595+
width, height = self.get_transform().transform((width, height))
15961596
inv_error = (1.0 / 1.89818e-6) * 0.5
15971597
if width < inv_error and height < inv_error:
15981598
self._path = Path.arc(theta1, theta2)
@@ -4168,8 +4168,7 @@ def get_path_in_displaycoord(self):
41684168
if self._posA_posB is not None:
41694169
posA = self._convert_xy_units(self._posA_posB[0])
41704170
posB = self._convert_xy_units(self._posA_posB[1])
4171-
posA = self.get_transform().transform_point(posA)
4172-
posB = self.get_transform().transform_point(posB)
4171+
(posA, posB) = self.get_transform().transform((posA, posB))
41734172
_path = self.get_connectionstyle()(posA, posB,
41744173
patchA=self.patchA,
41754174
patchB=self.patchB,
@@ -4327,7 +4326,7 @@ def _get_xy(self, x, y, s, axes=None):
43274326
trans = axes.transData
43284327
x = float(self.convert_xunits(x))
43294328
y = float(self.convert_yunits(y))
4330-
return trans.transform_point((x, y))
4329+
return trans.transform((x, y))
43314330
elif s == 'offset points':
43324331
# convert the data point
43334332
dx, dy = self.xy
@@ -4353,7 +4352,7 @@ def _get_xy(self, x, y, s, axes=None):
43534352
x = r * np.cos(theta)
43544353
y = r * np.sin(theta)
43554354
trans = axes.transData
4356-
return trans.transform_point((x, y))
4355+
return trans.transform((x, y))
43574356
elif s == 'figure points':
43584357
# points from the lower left corner of the figure
43594358
dpi = self.figure.dpi
@@ -4381,7 +4380,7 @@ def _get_xy(self, x, y, s, axes=None):
43814380
elif s == 'figure fraction':
43824381
# (0,0) is lower left, (1,1) is upper right of figure
43834382
trans = self.figure.transFigure
4384-
return trans.transform_point((x, y))
4383+
return trans.transform((x, y))
43854384
elif s == 'axes points':
43864385
# points from the lower left corner of the axes
43874386
dpi = self.figure.dpi
@@ -4415,9 +4414,9 @@ def _get_xy(self, x, y, s, axes=None):
44154414
elif s == 'axes fraction':
44164415
# (0,0) is lower left, (1,1) is upper right of axes
44174416
trans = axes.transAxes
4418-
return trans.transform_point((x, y))
4417+
return trans.transform((x, y))
44194418
elif isinstance(s, transforms.Transform):
4420-
return s.transform_point((x, y))
4419+
return s.transform((x, y))
44214420
else:
44224421
raise ValueError("{} is not a valid coordinate "
44234422
"transformation.".format(s))

lib/matplotlib/projections/geo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def _set_lim_and_transforms(self):
110110

111111
def _get_affine_transform(self):
112112
transform = self._get_core_transform(1)
113-
xscale, _ = transform.transform_point((np.pi, 0))
114-
_, yscale = transform.transform_point((0, np.pi / 2))
113+
xscale, _ = transform.transform((np.pi, 0))
114+
_, yscale = transform.transform((0, np.pi/2))
115115
return Affine2D() \
116116
.scale(0.5 / xscale, 0.5 / yscale) \
117117
.translate(0.5, 0.5)

lib/matplotlib/projections/polar.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -957,12 +957,12 @@ def draw(self, *args, **kwargs):
957957
if isinstance(self.patch, mpatches.Wedge):
958958
# Backwards-compatibility: Any subclassed Axes might override the
959959
# patch to not be the Wedge that PolarAxes uses.
960-
center = self.transWedge.transform_point((0.5, 0.5))
960+
center = self.transWedge.transform((0.5, 0.5))
961961
self.patch.set_center(center)
962962
self.patch.set_theta1(thetamin)
963963
self.patch.set_theta2(thetamax)
964964

965-
edge, _ = self.transWedge.transform_point((1, 0))
965+
edge, _ = self.transWedge.transform((1, 0))
966966
radius = edge - center[0]
967967
width = min(radius * (rmax - rmin) / rmax, radius)
968968
self.patch.set_radius(radius)
@@ -1419,7 +1419,7 @@ def start_pan(self, x, y, button):
14191419
mode = ''
14201420
if button == 1:
14211421
epsilon = np.pi / 45.0
1422-
t, r = self.transData.inverted().transform_point((x, y))
1422+
t, r = self.transData.inverted().transform((x, y))
14231423
if angle - epsilon <= t <= angle + epsilon:
14241424
mode = 'drag_r_labels'
14251425
elif button == 3:
@@ -1441,8 +1441,8 @@ def drag_pan(self, button, key, x, y):
14411441
p = self._pan_start
14421442

14431443
if p.mode == 'drag_r_labels':
1444-
startt, startr = p.trans_inverse.transform_point((p.x, p.y))
1445-
t, r = p.trans_inverse.transform_point((x, y))
1444+
(startt, startr), (t, r) = p.trans_inverse.transform(
1445+
[(p.x, p.y), (x, y)])
14461446

14471447
# Deal with theta
14481448
dt0 = t - startt
@@ -1463,8 +1463,8 @@ def drag_pan(self, button, key, x, y):
14631463
t.label2.set_ha(horiz2)
14641464

14651465
elif p.mode == 'zoom':
1466-
startt, startr = p.trans_inverse.transform_point((p.x, p.y))
1467-
t, r = p.trans_inverse.transform_point((x, y))
1466+
(startt, startr), (t, r) = p.trans_inverse.transform(
1467+
[(p.x, p.y), (x, y)])
14681468

14691469
# Deal with r
14701470
scale = r / startr

lib/matplotlib/quiver.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def _text_y(self, y):
346346
def draw(self, renderer):
347347
self._init()
348348
self.vector.draw(renderer)
349-
x, y = self.get_transform().transform_point((self.X, self.Y))
349+
x, y = self.get_transform().transform((self.X, self.Y))
350350
self.text.set_x(self._text_x(x))
351351
self.text.set_y(self._text_y(y))
352352
self.text.draw(renderer)
@@ -552,9 +552,7 @@ def _init(self):
552552
if True: # not self._initialized:
553553
trans = self._set_transform()
554554
ax = self.ax
555-
sx, sy = trans.inverted().transform_point(
556-
(ax.bbox.width, ax.bbox.height))
557-
self.span = sx
555+
self.span = trans.inverted().transform_bbox(ax.bbox).width
558556
if self.width is None:
559557
sn = np.clip(math.sqrt(self.N), 8, 25)
560558
self.width = 0.06 * self.span / sn

lib/matplotlib/tests/test_artist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_patch_transform_of_none():
2626

2727
# Draw an ellipse over data coord (2,2) by specifying device coords.
2828
xy_data = (2, 2)
29-
xy_pix = ax.transData.transform_point(xy_data)
29+
xy_pix = ax.transData.transform(xy_data)
3030

3131
# Not providing a transform of None puts the ellipse in data coordinates .
3232
e = mpatches.Ellipse(xy_data, width=1, height=1, fc='yellow', alpha=0.5)
@@ -68,7 +68,7 @@ def test_collection_transform_of_none():
6868

6969
# draw an ellipse over data coord (2,2) by specifying device coords
7070
xy_data = (2, 2)
71-
xy_pix = ax.transData.transform_point(xy_data)
71+
xy_pix = ax.transData.transform(xy_data)
7272

7373
# not providing a transform of None puts the ellipse in data coordinates
7474
e = mpatches.Ellipse(xy_data, width=1, height=1)

0 commit comments

Comments
 (0)
0