Skip to content

Navigation Menu

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 20b13ff

Browse filesBrowse files
authored
Merge pull request #20538 from anntzer/styleref
Show box/arrowstyle parameters in reference examples.
2 parents 8fec6ea + 9c596ab commit 20b13ff
Copy full SHA for 20b13ff

File tree

Expand file treeCollapse file tree

2 files changed

+50
-36
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+50
-36
lines changed

‎examples/shapes_and_collections/fancybox_demo.py

Copy file name to clipboardExpand all lines: examples/shapes_and_collections/fancybox_demo.py
+22-11Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
The following examples show how to plot boxes with different visual properties.
77
"""
88

9+
import inspect
10+
911
import matplotlib.pyplot as plt
1012
import matplotlib.transforms as mtransforms
1113
import matplotlib.patches as mpatch
@@ -15,17 +17,26 @@
1517
# First we'll show some sample boxes with fancybox.
1618

1719
styles = mpatch.BoxStyle.get_styles()
18-
spacing = 1.2
19-
20-
figheight = (spacing * len(styles) + .5)
21-
fig = plt.figure(figsize=(4 / 1.5, figheight / 1.5))
22-
fontsize = 0.3 * 72
23-
24-
for i, stylename in enumerate(styles):
25-
fig.text(0.5, (spacing * (len(styles) - i) - 0.5) / figheight, stylename,
26-
ha="center",
27-
size=fontsize,
28-
bbox=dict(boxstyle=stylename, fc="w", ec="k"))
20+
ncol = 2
21+
nrow = (len(styles) + 1) // ncol
22+
axs = (plt.figure(figsize=(3 * ncol, 1 + nrow))
23+
.add_gridspec(1 + nrow, ncol, wspace=.5).subplots())
24+
for ax in axs.flat:
25+
ax.set_axis_off()
26+
for ax in axs[0, :]:
27+
ax.text(.2, .5, "boxstyle",
28+
transform=ax.transAxes, size="large", color="tab:blue",
29+
horizontalalignment="right", verticalalignment="center")
30+
ax.text(.4, .5, "default parameters",
31+
transform=ax.transAxes,
32+
horizontalalignment="left", verticalalignment="center")
33+
for ax, (stylename, stylecls) in zip(axs[1:, :].T.flat, styles.items()):
34+
ax.text(.2, .5, stylename, bbox=dict(boxstyle=stylename, fc="w", ec="k"),
35+
transform=ax.transAxes, size="large", color="tab:blue",
36+
horizontalalignment="right", verticalalignment="center")
37+
ax.text(.4, .5, str(inspect.signature(stylecls))[1:-1].replace(", ", "\n"),
38+
transform=ax.transAxes,
39+
horizontalalignment="left", verticalalignment="center")
2940

3041

3142
###############################################################################

‎examples/text_labels_and_annotations/fancyarrow_demo.py

Copy file name to clipboardExpand all lines: examples/text_labels_and_annotations/fancyarrow_demo.py
+28-25Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,41 @@
66
Overview of the arrow styles available in `~.Axes.annotate`.
77
"""
88

9+
import inspect
10+
911
import matplotlib.patches as mpatches
1012
import matplotlib.pyplot as plt
1113

1214
styles = mpatches.ArrowStyle.get_styles()
13-
1415
ncol = 2
1516
nrow = (len(styles) + 1) // ncol
16-
figheight = (nrow + 0.5)
17-
fig = plt.figure(figsize=(4 * ncol / 1.5, figheight / 1.5))
18-
fontsize = 0.2 * 70
19-
20-
ax = fig.add_axes([0, 0, 1, 1], frameon=False)
21-
ax.set(xlim=(0, 4 * ncol), ylim=(0, figheight))
22-
23-
for i, (stylename, styleclass) in enumerate(styles.items()):
24-
x = 3.2 + (i // nrow) * 4
25-
y = (figheight - 0.7 - i % nrow) # /figheight
26-
p = mpatches.Circle((x, y), 0.2)
27-
ax.add_patch(p)
28-
29-
ax.annotate(stylename, (x, y),
30-
(x - 1.2, y),
31-
ha="right", va="center",
32-
size=fontsize,
33-
arrowprops=dict(arrowstyle=stylename,
34-
patchB=p,
35-
shrinkA=5,
36-
shrinkB=5,
37-
fc="k", ec="k",
38-
connectionstyle="arc3,rad=-0.05",
39-
),
17+
axs = (plt.figure(figsize=(4 * ncol, 1 + nrow))
18+
.add_gridspec(1 + nrow, ncol,
19+
wspace=.5, left=.1, right=.9, bottom=0, top=1).subplots())
20+
for ax in axs.flat:
21+
ax.set_axis_off()
22+
for ax in axs[0, :]:
23+
ax.text(0, .5, "arrowstyle",
24+
transform=ax.transAxes, size="large", color="tab:blue",
25+
horizontalalignment="center", verticalalignment="center")
26+
ax.text(.5, .5, "default parameters",
27+
transform=ax.transAxes,
28+
horizontalalignment="left", verticalalignment="center")
29+
for ax, (stylename, stylecls) in zip(axs[1:, :].T.flat, styles.items()):
30+
l, = ax.plot(.35, .5, "ok", transform=ax.transAxes)
31+
ax.annotate(stylename, (.35, .5), (0, .5),
32+
xycoords="axes fraction", textcoords="axes fraction",
33+
size="large", color="tab:blue",
34+
horizontalalignment="center", verticalalignment="center",
35+
arrowprops=dict(
36+
arrowstyle=stylename, connectionstyle="arc3,rad=-0.05",
37+
color="k", shrinkA=5, shrinkB=5, patchB=l,
38+
),
4039
bbox=dict(boxstyle="square", fc="w"))
40+
ax.text(.5, .5,
41+
str(inspect.signature(stylecls))[1:-1].replace(", ", "\n"),
42+
transform=ax.transAxes,
43+
horizontalalignment="left", verticalalignment="center")
4144

4245
plt.show()
4346

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.