8000 Extend joinstyle example · matplotlib/matplotlib@9687876 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9687876

Browse files
committed
Extend joinstyle example
1 parent 8466da0 commit 9687876

File tree

1 file changed

+60
-14
lines changed

1 file changed

+60
-14
lines changed

examples/lines_bars_and_markers/joinstyle.py

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
"""
2-
===========
3-
Join styles
4-
===========
2+
==========================
3+
Join styles and cap styles
4+
==========================
5+
6+
This example demonstrates the available join styles and cap styles.
7+
8+
Both are used in `.Line2D` and various ``Collections`` from
9+
`matplotlib.collections` as well as some functions that create these, e.g.
10+
`~matplotlib.pyplot.plot`.
511
6-
Illustrate the three different join styles.
712
"""
813

14+
#############################################################################
15+
#
16+
# Join styles
17+
# """""""""""
18+
#
19+
# Join styles define how the connection between two line segments is drawn.
20+
#
21+
# See the respective ``solid_joinstyle``, ``dash_joinstyle`` or ``joinstyle``
22+
# parameters.
23+
924
import numpy as np
1025
import matplotlib.pyplot as plt
1126

@@ -14,25 +29,56 @@ def plot_angle(ax, x, y, angle, style):
1429
phi = np.radians(angle)
1530
xx = [x + .5, x, x + .5*np.cos(phi)]
1631
yy = [y, y, y + .5*np.sin(phi)]
17-
ax.plot(xx, yy, lw=8, color='tab:blue', solid_joinstyle=style)
18-
ax.plot(xx[1:], yy[1:], lw=1, color='black')
19-
ax.plot(xx[1::-1], yy[1::-1], lw=1, color='black')
20-
ax.plot(xx[1:2], yy[1:2], 'o', color='tab:red', markersize=3)
21-
ax.text(x, y + .2, '%.0f degrees' % angle)
32+
ax.plot(xx, yy, lw=12, color='tab:blue', solid_joinstyle=style)
33+
ax.plot(xx, yy, lw=1, color='black')
34+
ax.plot(xx[1], yy[1], 'o', color='tab:red', markersize=3)
2235

2336

24-
fig, ax = plt.subplots()
37+
fig, ax = plt.subplots(figsize=(8, 6))
2538
ax.set_title('Join style')
2639

27-
for x, style in enumerate((('miter', 'round', 'bevel'))):
40+
for x, style in enumerate(['miter', 'round', 'bevel']):
2841
ax.text(x, 5, style)
29-
for i in range(5):
30-
plot_angle(ax, x, i, pow(2.0, 3 + i), style)
42+
for y, angle in enumerate([20, 45, 60, 90, 120]):
43+
plot_angle(ax, x, y, angle, style)
44+
if x == 0:
45+
ax.text(-1.3, y, f'{angle} degrees')
46+
ax.text(1, 4.7, '(default)')
3147

32-
ax.set_xlim(-.5, 2.75)
48+
ax.set_xlim(-1.5, 2.75)
3349
ax.set_ylim(-.5, 5.5)
50+
ax.xaxis.set_visible(False)
51+
ax.yaxis.set_visible(False)
3452
plt.show()
3553

54+
55+
#############################################################################
56+
#
57+
# Cap styles
58+
# """"""""""
59+
#
60+
# Cap styles define how the the end of a line is drawn.
61+
#
62+
# See the respective ``solid_capstyle``, ``dash_capstyle`` or ``capstyle``
63+
# parameters.
64+
65+
fig, ax = plt.subplots(figsize=(8, 2))
66+
ax.set_title('Cap style')
67+
68+
for x, style in enumerate(['butt', 'round', 'projecting']):
69+
ax.text(x, 1, style)
70+
xx = [x, x+0.5]
71+
yy = [0, 0]
72+
ax.plot(xx, yy, lw=12, color='tab:blue', solid_capstyle=style)
73+
ax.plot(xx, yy, lw=1, color='black')
74+
ax.plot(xx, yy, 'o', color='tab:red', markersize=3)
75+
ax.text(2, 0.7, '(default)')
76+
77+
ax.set_ylim(-.5, 1.5)
78+
ax.xaxis.set_visible(False)
79+
ax.yaxis.set_visible(False)
80+
81+
3682
#############################################################################
3783
#
3884
# ------------

0 commit comments

Comments
 (0)
0