8000 Merge pull request #29801 from timhoffm/doc-arrowstyle · matplotlib/matplotlib@05663f7 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

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 05663f7

Browse files
authored
Merge pull request #29801 from timhoffm/doc-arrowstyle
2 parents b2b76d6 + 1c39a10 commit 05663f7

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

galleries/examples/text_labels_and_annotations/fancyarrow_demo.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
Annotation arrow style reference
44
================================
55
6-
Overview of the arrow styles available in `~.Axes.annotate`.
6+
Overview of the available `.ArrowStyle` settings. These are used for the *arrowstyle*
7+
parameter of `~.Axes.annotate` and `.FancyArrowPatch`.
8+
9+
Each style can be configured with a set of parameters, which are stated along with
10+
their default values.
711
"""
812

913
import inspect
@@ -12,38 +16,38 @@
1216

1317
import matplotlib.pyplot as plt
1418

15-
import matplotlib.patches as mpatches
19+
from matplotlib.patches import ArrowStyle
1620

17 10000 -
styles = mpatches.ArrowStyle.get_styles()
21+
styles = ArrowStyle.get_styles()
1822
ncol = 2
1923
nrow = (len(styles) + 1) // ncol
20-
axs = (plt.figure(figsize=(4 * ncol, 1 + nrow))
21-
.add_gridspec(1 + nrow, ncol,
22-
wspace=0, hspace=0, left=0, right=1, bottom=0, top=1).subplots())
24+
gridspec_kw = dict(wspace=0, hspace=0.05, left=0, right=1, bottom=0, top=1)
25+
fig, axs = plt.subplots(1 + nrow, ncol,
26+
figsize=(4 * ncol, 1 + nrow), gridspec_kw=gridspec_kw)
2327
for ax in axs.flat:
24-
ax.set_xlim(-0.5, 4)
28+
ax.set_xlim(-0.1, 4)
2529
ax.set_axis_off()
2630
for ax in axs[0, :]:
27-
ax.text(-0.25, 0.5, "arrowstyle", size="large", color="tab:blue")
28-
ax.text(1.25, .5, "default parameters", size="large")
31+
ax.text(0, 0.5, "arrowstyle", size="large", color="tab:blue")
32+
ax.text(1.4, .5, "default parameters", size="large")
2933
for ax, (stylename, stylecls) in zip(axs[1:, :].T.flat, styles.items()):
3034
# draw dot and annotation with arrowstyle
31-
l, = ax.plot(1, 0, "o", color="grey")
32-
ax.annotate(stylename, (1, 0), (0, 0),
33-
size="large", color="tab:blue", ha="center", va="center",
35+
l, = ax.plot(1.25, 0, "o", color="darkgrey")
36+
ax.annotate(stylename, (1.25, 0), (0, 0),
37+
size="large", color="tab:blue", va="center", family="monospace",
3438
arrowprops=dict(
35-
arrowstyle=stylename, connectionstyle="arc3,rad=-0.05",
36-
color="k", shrinkA=5, shrinkB=5, patchB=l,
39+
arrowstyle=stylename, connectionstyle="arc3,rad=0",
40+
color="black", shrinkA=5, shrinkB=5, patchB=l,
3741
),
38-
bbox=dict(boxstyle="square", fc="w", ec="grey"))
42+
bbox=dict(boxstyle="square", fc="w", ec="darkgrey"))
3943
# draw default parameters
4044
# wrap at every nth comma (n = 1 or 2, depending on text length)
4145
s = str(inspect.signature(stylecls))[1:-1]
4246
n = 2 if s.count(',') > 3 else 1
43-
ax.text(1.25, 0,
47+
ax.text(1.4, 0,
4448
re.sub(', ', lambda m, c=itertools.count(1): m.group()
4549
if next(c) % n else '\n', s),
46-
verticalalignment="center")
50+
verticalalignment="center", color="0.3")
4751

4852
plt.show()
4953

0 commit comments

Comments
 (0)
0