8000 Merge pull request #15858 from anntzer/1tuple · matplotlib/matplotlib@cf6c569 · GitHub
[go: up one dir, main page]

Skip to content

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

Appearance settings

Commit cf6c569

Browse files
authored
Merge pull request #15858 from anntzer/1tuple
MNT: Avoid some uses of len-1 tuples.
2 parents 88b1abf + 743dcff commit cf6c569

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,11 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
684684
xmax, ymax = points_max
685685

686686
streamarr = np.empty(
687-
(shape[0] * shape[1],),
688-
dtype=[('flags', 'u1'),
689-
('points', '>u4', (2,)),
690-
('colors', 'u1', (3,))])
687+
shape[0] * shape[1],
688+
dtype=[('flags', 'u1'), ('points', '2>u4'), ('colors', '3u1')])
691689
streamarr['flags'] = 0
692690
streamarr['points'] = (flat_points - points_min) * factor
693691
streamarr['colors'] = flat_colors[:, :3] * 255.0
694-
695692
stream = quote_ps_string(streamarr.tostring())
696693

697694
self._pswriter.write(f"""\

lib/matplotlib/offsetbox.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def _get_packed_offsets(wd_list, total, sep, mode="fixed"):
9191
offsets : array of float
9292
The left offsets of the boxes.
9393
"""
94-
w_list, d_list = zip(*wd_list)
95-
# d_list is currently not used.
94+
w_list, d_list = zip(*wd_list) # d_list is currently not used.
95+
cbook._check_in_list(["fixed", "expand", "equal"], mode=mode)
9696

9797
if mode == "fixed":
9898
offsets_ = np.cumsum([0] + [w + sep for w in w_list])
@@ -119,16 +119,13 @@ def _get_packed_offsets(wd_list, total, sep, mode="fixed"):
119119
if total is None:
120120
if sep is None:
121121
raise ValueError("total and sep cannot both be None when "
122-
"using layout mode 'equal'.")
122+
"using layout mode 'equal'")
123123
total = (maxh + sep) * len(w_list)
124124
else:
125125
sep = total / len(w_list) - maxh
126126
offsets = (maxh + sep) * np.arange(len(w_list))
127127
return total, offsets
128128

129-
else:
130-
raise ValueError("Unknown mode : %s" % (mode,))
131-
132129

133130
def _get_aligned_offsets(hd_list, height, align="baseline"):
134131
"""
@@ -146,6 +143,8 @@ def _get_aligned_offsets(hd_list, height, align="baseline"):
146143

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

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

167164
return height, descent, offsets
168165

lib/matplotlib/patches.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,14 +3864,11 @@ class FancyArrowPatch(Patch):
38643864
_edge_default = True
38653865

38663866
def __str__(self):
3867-
38683867
if self._posA_posB is not None:
38693868
(x1, y1), (x2, y2) = self._posA_posB
3870-
return self.__class__.__name__ \
3871-
+ "((%g, %g)->(%g, %g))" % (x1, y1, x2, y2)
3869+
return f"{type(self).__name__}(({x1:g}, {y1:g})->({x2:g}, {y2:g}))"
38723870
else:
3873-
return self.__class__.__name__ \
3874-
+ "(%s)" % (str(self._path_original),)
3871+
return f"{type(self).__name__}({self._path_original})"
38753872

38763873
@docstring.dedent_interpd
38773874
def __init__(self, posA=None, posB=None,

lib/matplotlib/path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ def unit_regular_star(cls, numVertices, innerCircle=0.5):
688688
theta += np.pi / 2.0
689689
r = np.ones(ns2 + 1)
690690
r[1::2] = innerCircle
691-
verts = np.vstack((r*np.cos(theta), r*np.sin(theta))).transpose()
692-
codes = np.empty((ns2 + 1,))
691+
verts = (r * np.vstack((np.cos(theta), np.sin(theta)))).T
692+
codes = np.empty(ns2 + 1)
693693
codes[0] = cls.MOVETO
694694
codes[1:-1] = cls.LINETO
695695
codes[-1] = cls.CLOSEPOLY

0 commit comments

Comments
 (0)
0