Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18bc802

Browse files
authored
Merge pull request #14845 from anntzer/inverted
More cleanups.
2 parents c7ab2be + 7bf0185 commit 18bc802

File tree

5 files changed

+30
-61
lines changed

5 files changed

+30
-61
lines changed

lib/matplotlib/image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
501501

502502
# Subset the input image to only the part that will be
503503
# displayed
504-
subset = TransformedBbox(
505-
clip_bbox, t0.frozen().inverted()).frozen()
504+
subset = TransformedBbox(clip_bbox, t0.inverted()).frozen()
506505
output = output[
507506
int(max(subset.ymin, 0)):
508507
int(min(subset.ymax + 1, output.shape[0])),

lib/matplotlib/patches.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,11 +1638,10 @@ def iter_circle_intersect_on_line_seg(x0, y0, x1, y1):
16381638
yield x, y
16391639

16401640
# Transforms the axes box_path so that it is relative to the unit
1641-
# circle in the same way that it is relative to the desired
1642-
# ellipse.
1641+
# circle in the same way that it is relative to the desired ellipse.
16431642
box_path = Path.unit_rectangle()
1644-
box_path_transform = transforms.BboxTransformTo(self.axes.bbox) + \
1645-
self.get_transform().inverted()
1643+
box_path_transform = (transforms.BboxTransformTo(self.axes.bbox)
1644+
- self.get_transform())
16461645
box_path = box_path.transformed(box_path_transform)
16471646

16481647
thetas = set()
@@ -4146,10 +4145,8 @@ def get_path(self):
41464145
in display coordinates.
41474146
"""
41484147
_path, fillable = self.get_path_in_displaycoord()
4149-
41504148
if np.iterable(fillable):
41514149
_path = concatenate_paths(_path)
4152-
41534150
return self.get_transform().inverted().transform_path(_path)
41544151

41554152
def get_path_in_displaycoord(self):

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ def get_tick_iterators(self, axes):
9696
# c, angle, l is position, tick angle, and label
9797
9898
return iter_major, iter_minor
99-
100-
10199
"""
102100

103101
class _Base:
@@ -138,7 +136,7 @@ def __init__(self, loc, nth_coord=None):
138136

139137
_verts = np.array([[0., 0.],
140138
[1., 1.]])
141-
fixed_coord = 1-nth_coord
139+
fixed_coord = 1 - nth_coord
142140
_verts[:, fixed_coord] = self.passthru_pt[fixed_coord]
143141

144142
# axis line in transAxes
@@ -166,21 +164,16 @@ def get_axislabel_pos_angle(self, axes):
166164
167165
get_label_transform() returns a transform of (transAxes+offset)
168166
"""
169-
loc = self._loc
170-
pos, angle_tangent = dict(left=((0., 0.5), 90),
171-
right=((1., 0.5), 90),
172-
bottom=((0.5, 0.), 0),
173-
top=((0.5, 1.), 0))[loc]
174-
175-
return pos, angle_tangent
167+
return dict(left=((0., 0.5), 90), # (position, angle_tangent)
168+
right=((1., 0.5), 90),
169+
bottom=((0.5, 0.), 0),
170+
top=((0.5, 1.), 0))[self._loc]
176171

177172
# TICK
178173

179174
def get_tick_transform(self, axes):
180-
trans_tick = [axes.get_xaxis_transform(),
181-
axes.get_yaxis_transform()][self.nth_coord]
182-
183-
return trans_tick
175+
return [axes.get_xaxis_transform(),
176+
axes.get_yaxis_transform()][self.nth_coord]
184177

185178
class Floating(_Base):
186179

@@ -229,9 +222,7 @@ def get_tick_iterators(self, axes):
229222
minorLocs = minor.locator()
230223
minorLabels = minor.formatter.format_ticks(minorLocs)
231224

232-
trans_tick = self.get_tick_transform(axes)
233-
234-
tr2ax = trans_tick + axes.transAxes.inverted()
225+
tick_to_axes = self.get_tick_transform(axes) - axes.transAxes
235226

236227
def _f(locs, labels):
237228
for x, l in zip(locs, labels):
@@ -240,7 +231,7 @@ def _f(locs, labels):
240231
c[self.nth_coord] = x
241232

242233
# check if the tick point is inside axes
243-
c2 = tr2ax.transform(c)
234+
c2 = tick_to_axes.transform(c)
244235
if (0 - self.delta1
245236
<= c2[self.nth_coord]
246237
<= 1 + self.delta2):
@@ -260,8 +251,8 @@ def get_line(self, axes):
260251
[1., 1.]])
261252

262253
fixed_coord = 1 - self.nth_coord
263-
p = (axes.transData + axes.transAxes.inverted()).transform(
264-
[self._value, self._value])
254+
data_to_axes = axes.transData - axes.transAxes
255+
p = data_to_axes.transform([self._value, self._value])
265256
_verts[:, fixed_coord] = p[fixed_coord]
266257

267258
return Path(_verts)
@@ -278,42 +269,27 @@ def get_axislabel_pos_angle(self, axes):
278269
279270
get_label_transform() returns a transform of (transAxes+offset)
280271
"""
281-
if self.nth_coord == 0:
282-
angle = 0
283-
else:
284-
angle = 90
285-
272+
angle = [0, 90][self.nth_coord]
286273
_verts = [0.5, 0.5]
287-
288-
fixed_coord = 1-self.nth_coord
289-
p = (axes.transData + axes.transAxes.inverted()).transform(
290-
[self._value, self._value])
274+
fixed_coord = 1 - self.nth_coord
275+
data_to_axes = axes.transData - axes.transAxes
276+
p = data_to_axes.transform([self._value, self._value])
291277
_verts[fixed_coord] = p[fixed_coord]
292-
if not (0. <= _verts[fixed_coord] <= 1.):
293-
return None, None
294-
else:
278+
if 0 <= _verts[fixed_coord] <= 1:
295279
return _verts, angle
280+
else:
281+
return None, None
296282

297283
def get_tick_transform(self, axes):
298284
return axes.transData
299285

300286
def get_tick_iterators(self, axes):
301287
"""tick_loc, tick_angle, tick_label"""
302-
303-
loc = self._axis_direction
304-
305-
if loc in ["bottom", "top"]:
306-
angle_normal, angle_tangent = 90, 0
307-
else:
308-
angle_normal, angle_tangent = 0, 90
309-
310288
if self.nth_coord == 0:
311289
angle_normal, angle_tangent = 90, 0
312290
else:
313291
angle_normal, angle_tangent = 0, 90
314292

315-
# angle = 90 - 90 * self.nth_coord
316-
317293
major = self.axis.major
318294
majorLocs = major.locator()
319295
majorLabels = major.formatter.format_ticks(majorLocs)
@@ -322,14 +298,13 @@ def get_tick_iterators(self, axes):
322298
minorLocs = minor.locator()
323299
minorLabels = minor.formatter.format_ticks(minorLocs)
324300

325-
tr2ax = axes.transData + axes.transAxes.inverted()
301+
data_to_axes = axes.transData - axes.transAxes
326302

327303
def _f(locs, labels):
328304
for x, l in zip(locs, labels):
329-
330305
c = [self._value, self._value]
331306
c[self.nth_coord] = x
332-
c1, c2 = tr2ax.transform(c)
307+
c1, c2 = data_to_axes.transform(c)
333308
if (0 <= c1 <= 1 and 0 <= c2 <= 1
334309
and 0 - self.delta1
335310
<= [c1, c2][self.nth_coord]

lib/mpl_toolkits/axisartist/floating_axes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,9 @@ def f1():
123123
mm = (yy1b - yy1a == 0) & (xx1b - xx1a == 0) # mask not defined dd
124124
dd[mm] = dd2[mm] + np.pi / 2
125125

126-
trans_tick = self.get_tick_transform(axes)
127-
tr2ax = trans_tick + axes.transAxes.inverted()
126+
tick_to_axes = self.get_tick_transform(axes) - axes.transAxes
128127
for x, y, d, d2, lab in zip(xx1, yy1, dd, dd2, labels):
129-
c2 = tr2ax.transform((x, y))
128+
c2 = tick_to_axes.transform((x, y))
130129
delta = 0.00001
131130
if 0-delta <= c2[0] <= 1+delta and 0-delta <= c2[1] <= 1+delta:
132131
d1, d2 = np.rad2deg([d, d2])

lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def get_axislabel_pos_angle(self, axes):
161161
grid_finder = self.grid_helper.grid_finder
162162
(xx1,), (yy1,) = grid_finder.transform_xy([xx0], [yy0])
163163

164-
trans_passingthrough_point = axes.transData + axes.transAxes.inverted()
165-
p = trans_passingthrough_point.transform([xx1, yy1])
164+
data_to_axes = axes.transData - axes.transAxes
165+
p = data_to_axes.transform([xx1, yy1])
166166

167167
if 0 <= p[0] <= 1 and 0 <= p[1] <= 1:
168168
xx1c, yy1c = axes.transData.transform([xx1, yy1])
@@ -253,10 +253,9 @@ def f1():
253253
mm = (yy1b == yy1a) & (xx1b == xx1a) # mask where dd not defined
254254
dd[mm] = dd2[mm] + np.pi / 2
255255

256-
trans_tick = self.get_tick_transform(axes)
257-
tr2ax = trans_tick + axes.transAxes.inverted()
256+
tick_to_axes = self.get_tick_transform(axes) - axes.transAxes
258257
for x, y, d, d2, lab in zip(xx1, yy1, dd, dd2, labels):
259-
c2 = tr2ax.transform((x, y))
258+
c2 = tick_to_axes.transform((x, y))
260259
delta = 0.00001
261260
if 0-delta <= c2[0] <= 1+delta and 0-delta <= c2[1] <= 1+delta:
262261
d1, d2 = np.rad2deg([d, d2])

0 commit comments

Comments
 (0)