Skip to content

More cleanups. #14845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,

# Subset the input image to only the part that will be
# displayed
subset = TransformedBbox(
clip_bbox, t0.frozen().inverted()).frozen()
subset = TransformedBbox(clip_bbox, t0.inverted()).frozen()
output = output[
int(max(subset.ymin, 0)):
int(min(subset.ymax + 1, output.shape[0])),
Expand Down
9 changes: 3 additions & 6 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,11 +1638,10 @@ def iter_circle_intersect_on_line_seg(x0, y0, x1, y1):
yield x, y

# Transforms the axes box_path so that it is relative to the unit
# circle in the same way that it is relative to the desired
# ellipse.
# circle in the same way that it is relative to the desired ellipse.
box_path = Path.unit_rectangle()
box_path_transform = transforms.BboxTransformTo(self.axes.bbox) + \
self.get_transform().inverted()
box_path_transform = (transforms.BboxTransformTo(self.axes.bbox)
- self.get_transform())
box_path = box_path.transformed(box_path_transform)

thetas = set()
Expand Down Expand Up @@ -4146,10 +4145,8 @@ def get_path(self):
in display coordinates.
"""
_path, fillable = self.get_path_in_displaycoord()

if np.iterable(fillable):
_path = concatenate_paths(_path)

return self.get_transform().inverted().transform_path(_path)

def get_path_in_displaycoord(self):
Expand Down
65 changes: 20 additions & 45 deletions lib/mpl_toolkits/axisartist/axislines.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ def get_tick_iterators(self, axes):
# c, angle, l is position, tick angle, and label

return iter_major, iter_minor


"""

class _Base:
Expand Down Expand Up @@ -138,7 +136,7 @@ def __init__(self, loc, nth_coord=None):

_verts = np.array([[0., 0.],
[1., 1.]])
fixed_coord = 1-nth_coord
fixed_coord = 1 - nth_coord
_verts[:, fixed_coord] = self.passthru_pt[fixed_coord]

# axis line in transAxes
Expand Down Expand Up @@ -166,21 +164,16 @@ def get_axislabel_pos_angle(self, axes):

get_label_transform() returns a transform of (transAxes+offset)
"""
loc = self._loc
pos, angle_tangent = dict(left=((0., 0.5), 90),
right=((1., 0.5), 90),
bottom=((0.5, 0.), 0),
top=((0.5, 1.), 0))[loc]

return pos, angle_tangent
return dict(left=((0., 0.5), 90), # (position, angle_tangent)
right=((1., 0.5), 90),
bottom=((0.5, 0.), 0),
top=((0.5, 1.), 0))[self._loc]

# TICK

def get_tick_transform(self, axes):
trans_tick = [axes.get_xaxis_transform(),
axes.get_yaxis_transform()][self.nth_coord]

return trans_tick
return [axes.get_xaxis_transform(),
axes.get_yaxis_transform()][self.nth_coord]

class Floating(_Base):

Expand Down Expand Up @@ -229,9 +222,7 @@ def get_tick_iterators(self, axes):
minorLocs = minor.locator()
minorLabels = minor.formatter.format_ticks(minorLocs)

trans_tick = self.get_tick_transform(axes)

tr2ax = trans_tick + axes.transAxes.inverted()
tick_to_axes = self.get_tick_transform(axes) - axes.transAxes

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

# check if the tick point is inside axes
c2 = tr2ax.transform(c)
c2 = tick_to_axes.transform(c)
if (0 - self.delta1
<= c2[self.nth_coord]
<= 1 + self.delta2):
Expand All @@ -260,8 +251,8 @@ def get_line(self, axes):
[1., 1.]])

fixed_coord = 1 - self.nth_coord
p = (axes.transData + axes.transAxes.inverted()).transform(
[self._value, self._value])
data_to_axes = axes.transData - axes.transAxes
p = data_to_axes.transform([self._value, self._value])
_verts[:, fixed_coord] = p[fixed_coord]

return Path(_verts)
Expand All @@ -278,42 +269,27 @@ def get_axislabel_pos_angle(self, axes):

get_label_transform() returns a transform of (transAxes+offset)
"""
if self.nth_coord == 0:
angle = 0
else:
angle = 90

angle = [0, 90][self.nth_coord]
_verts = [0.5, 0.5]

fixed_coord = 1-self.nth_coord
p = (axes.transData + axes.transAxes.inverted()).transform(
[self._value, self._value])
fixed_coord = 1 - self.nth_coord
data_to_axes = axes.transData - axes.transAxes
p = data_to_axes.transform([self._value, self._value])
_verts[fixed_coord] = p[fixed_coord]
if not (0. <= _verts[fixed_coord] <= 1.):
return None, None
else:
if 0 <= _verts[fixed_coord] <= 1:
return _verts, angle
else:
return None, None

def get_tick_transform(self, axes):
return axes.transData

def get_tick_iterators(self, axes):
"""tick_loc, tick_angle, tick_label"""

loc = self._axis_direction

if loc in ["bottom", "top"]:
angle_normal, angle_tangent = 90, 0
else:
angle_normal, angle_tangent = 0, 90

if self.nth_coord == 0:
angle_normal, angle_tangent = 90, 0
else:
angle_normal, angle_tangent = 0, 90

# angle = 90 - 90 * self.nth_coord

major = self.axis.major
majorLocs = major.locator()
majorLabels = major.formatter.format_ticks(majorLocs)
Expand All @@ -322,14 +298,13 @@ def get_tick_iterators(self, axes):
minorLocs = minor.locator()
minorLabels = minor.formatter.format_ticks(minorLocs)

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

def _f(locs, labels):
for x, l in zip(locs, labels):

c = [self._value, self._value]
c[self.nth_coord] = x
c1, c2 = tr2ax.transform(c)
c1, c2 = data_to_axes.transform(c)
if (0 <= c1 <= 1 and 0 <= c2 <= 1
and 0 - self.delta1
<= [c1, c2][self.nth_coord]
Expand Down
5 changes: 2 additions & 3 deletions lib/mpl_toolkits/axisartist/floating_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ def f1():
mm = (yy1b - yy1a == 0) & (xx1b - xx1a == 0) # mask not defined dd
dd[mm] = dd2[mm] + np.pi / 2

trans_tick = self.get_tick_transform(axes)
tr2ax = trans_tick + axes.transAxes.inverted()
tick_to_axes = self.get_tick_transform(axes) - axes.transAxes
for x, y, d, d2, lab in zip(xx1, yy1, dd, dd2, labels):
c2 = tr2ax.transform((x, y))
c2 = tick_to_axes.transform((x, y))
delta = 0.00001
if 0-delta <= c2[0] <= 1+delta and 0-delta <= c2[1] <= 1+delta:
d1, d2 = np.rad2deg([d, d2])
Expand Down
9 changes: 4 additions & 5 deletions lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def get_axislabel_pos_angle(self, axes):
grid_finder = self.grid_helper.grid_finder
(xx1,), (yy1,) = grid_finder.transform_xy([xx0], [yy0])

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

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

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