8000 Avoid some uses of len-1 tuples. by anntzer · Pull Request #15858 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Avoid some uses of len-1 tuples. #15858

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
Dec 8, 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
7 changes: 2 additions & 5 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,14 +684,11 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
xmax, ymax = points_max

streamarr = np.empty(
(shape[0] * shape[1],),
dtype=[('flags', 'u1'),
('points', '>u4', (2,)),
('colors', 'u1', (3,))])
shape[0] * shape[1],
dtype=[('flags', 'u1'), ('points', '2>u4'), ('colors', '3u1')])
streamarr['flags'] = 0
streamarr['points'] = (flat_points - points_min) * factor
streamarr['colors'] = flat_colors[:, :3] * 255.0

stream = quote_ps_string(streamarr.tostring())

self._pswriter.write(f"""\
Expand Down
13 changes: 5 additions & 8 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def _get_packed_offsets(wd_list, total, sep, mode="fixed"):
offsets : array of float
The left offsets of the boxes.
"""
w_list, d_list = zip(*wd_list)
# d_list is currently not used.
w_list, d_list = zip(*wd_list) # d_list is currently not used.
cbook._check_in_list(["fixed", "expand", "equal"], mode=mode)

if mode == "fixed":
offsets_ = np.cumsum([0] + [w + sep for w in w_list])
Expand All @@ -119,16 +119,13 @@ def _get_packed_offsets(wd_list, total, sep, mode="fixed"):
if total is None:
if sep is None:
raise ValueError("total and sep cannot both be None when "
"using layout mode 'equal'.")
"using layout mode 'equal'")
total = (maxh + sep) * len(w_list)
else:
sep = total / len(w_list) - maxh
offsets = (maxh + sep) * np.arange(len(w_list))
return total, offsets

else:
raise ValueError("Unknown mode : %s" % (mode,))


def _get_aligned_offsets(hd_list, height, align="baseline"):
"""
Expand All @@ -146,6 +143,8 @@ def _get_aligned_offsets(hd_list, height, align="baseline"):

if height is None:
height = max(h for h, d in hd_list)
cbook._check_in_list(
["baseline", "left", "top", "right", "bottom", "center"], align=align)

if align == "baseline":
height_descent = max(h - d for h, d in hd_list)
Expand All @@ -161,8 +160,6 @@ def _get_aligned_offsets(hd_list, height, align="baseline"):
elif align == "center":
descent = 0.
offsets = [(height - h) * .5 + d for h, d in hd_list]
else:
raise ValueError("Unknown Align mode : %s" % (align,))

return height, descent, offsets

Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3864,14 +3864,11 @@ class FancyArrowPatch(Patch):
_edge_default = True

def __str__(self):

if self._posA_posB is not None:
(x1, y1), (x2, y2) = self._posA_posB
return self.__class__.__name__ \
+ "((%g, %g)->(%g, %g))" % (x1, y1, x2, y2)
return f"{type(self).__name__}(({x1:g}, {y1:g})->({x2:g}, {y2:g}))"
else:
return self.__class__.__name__ \
+ "(%s)" % (str(self._path_original),)
return f"{type(self).__name__}({self._path_original})"

@docstring.dedent_interpd
def __init__(self, posA=None, posB=None,
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,8 @@ def unit_regular_star(cls, numVertices, innerCircle=0.5):
theta += np.pi / 2.0
r = np.ones(ns2 + 1)
r[1::2] = innerCircle
verts = np.vstack((r*np.cos(theta), r*np.sin(theta))).transpose()
codes = np.empty((ns2 + 1,))
verts = (r * np.vstack((np.cos(theta), np.sin(theta)))).T
codes = np.empty(ns2 + 1)
codes[0] = cls.MOVETO
codes[1:-1] = cls.LINETO
codes[-1] = cls.CLOSEPOLY
Expand Down
0