Skip to content

Commit 3796813

Browse files
authored
Merge pull request matplotlib#30596 from anntzer/dd
Cleanup donuts example.
2 parents f8400db + a00cbed commit 3796813

File tree

1 file changed

+6
-15
lines changed
  • galleries/examples/shapes_and_collections

1 file changed

+6
-15
lines changed

galleries/examples/shapes_and_collections/donut.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,21 @@
1515

1616

1717
def wise(v):
18-
if v == 1:
19-
return "CCW"
20-
else:
21-
return "CW"
18+
return {+1: "CCW", -1: "CW"}[v]
2219

2320

2421
def make_circle(r):
2522
t = np.arange(0, np.pi * 2.0, 0.01)
26-
t = t.reshape((len(t), 1))
2723
x = r * np.cos(t)
2824
y = r * np.sin(t)
29-
return np.hstack((x, y))
25+
return np.column_stack((x, y))
3026

31-
Path = mpath.Path
3227

3328
fig, ax = plt.subplots()
3429

3530
inside_vertices = make_circle(0.5)
3631
outside_vertices = make_circle(1.0)
37-
codes = np.ones(
38-
len(inside_vertices), dtype=mpath.Path.code_type) * mpath.Path.LINETO
32+
codes = np.full(len(inside_vertices), mpath.Path.LINETO)
3933
codes[0] = mpath.Path.MOVETO
4034

4135
for i, (inside, outside) in enumerate(((1, 1), (1, -1), (-1, 1), (-1, -1))):
@@ -44,23 +38,20 @@ def make_circle(r):
4438
vertices = np.concatenate((outside_vertices[::outside],
4539
inside_vertices[::inside]))
4640
# Shift the path
47-
vertices[:, 0] += i * 2.5
41+
vertices += (i * 2.5, 0)
4842
# The codes will be all "LINETO" commands, except for "MOVETO"s at the
4943
# beginning of each subpath
5044
all_codes = np.concatenate((codes, codes))
5145
# Create the Path object
5246
path = mpath.Path(vertices, all_codes)
53-
# Add plot it
47+
# And plot it
5448
patch = mpatches.PathPatch(path, facecolor='#885500', edgecolor='black')
5549
ax.add_patch(patch)
5650

5751
ax.annotate(f"Outside {wise(outside)},\nInside {wise(inside)}",
5852
(i * 2.5, -1.5), va="top", ha="center")
5953

60-
ax.set_xlim(-2, 10)
61-
ax.set_ylim(-3, 2)
62-
ax.set_title('Mmm, donuts!')
63-
ax.set_aspect(1.0)
54+
ax.set(xlim=(-2, 10), ylim=(-3, 2), aspect=1, title="Mmm, donuts!")
6455
plt.show()
6556

6657
# %%

0 commit comments

Comments
 (0)