Skip to content

Show box/arrowstyle parameters in reference examples. #20538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions examples/shapes_and_collections/fancybox_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
The following examples show how to plot boxes with different visual properties.
"""

import inspect

import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
import matplotlib.patches as mpatch
Expand All @@ -15,17 +17,26 @@
# First we'll show some sample boxes with fancybox.

styles = mpatch.BoxStyle.get_styles()
spacing = 1.2

figheight = (spacing * len(styles) + .5)
fig = plt.figure(figsize=(4 / 1.5, figheight / 1.5))
fontsize = 0.3 * 72

for i, stylename in enumerate(styles):
fig.text(0.5, (spacing * (len(styles) - i) - 0.5) / figheight, stylename,
ha="center",
size=fontsize,
bbox=dict(boxstyle=stylename, fc="w", ec="k"))
ncol = 2
nrow = (len(styles) + 1) // ncol
axs = (plt.figure(figsize=(3 * ncol, 1 + nrow))
.add_gridspec(1 + nrow, ncol, wspace=.5).subplots())
for ax in axs.flat:
ax.set_axis_off()
for ax in axs[0, :]:
ax.text(.2, .5, "boxstyle",
transform=ax.transAxes, size="large", color="tab:blue",
horizontalalignment="right", verticalalignment="center")
ax.text(.4, .5, "default parameters",
transform=ax.transAxes,
horizontalalignment="left", verticalalignment="center")
for ax, (stylename, stylecls) in zip(axs[1:, :].T.flat, styles.items()):
ax.text(.2, .5, stylename, bbox=dict(boxstyle=stylename, fc="w", ec="k"),
transform=ax.transAxes, size="large", color="tab:blue",
horizontalalignment="right", verticalalignment="center")
ax.text(.4, .5, str(inspect.signature(stylecls))[1:-1].replace(", ", "\n"),
transform=ax.transAxes,
horizontalalignment="left", verticalalignment="center")


###############################################################################
Expand Down
53 changes: 28 additions & 25 deletions examples/text_labels_and_annotations/fancyarrow_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,41 @@
Overview of the arrow styles available in `~.Axes.annotate`.
"""

import inspect

import matplotlib.patches as mpatches
import matplotlib.pyplot as plt

styles = mpatches.ArrowStyle.get_styles()

ncol = 2
nrow = (len(styles) + 1) // ncol
figheight = (nrow + 0.5)
fig = plt.figure(figsize=(4 * ncol / 1.5, figheight / 1.5))
fontsize = 0.2 * 70

ax = fig.add_axes([0, 0, 1, 1], frameon=False)
ax.set(xlim=(0, 4 * ncol), ylim=(0, figheight))

for i, (stylename, styleclass) in enumerate(styles.items()):
x = 3.2 + (i // nrow) * 4
y = (figheight - 0.7 - i % nrow) # /figheight
p = mpatches.Circle((x, y), 0.2)
ax.add_patch(p)

ax.annotate(stylename, (x, y),
(x - 1.2, y),
ha="right", va="center",
size=fontsize,
arrowprops=dict(arrowstyle=stylename,
patchB=p,
shrinkA=5,
shrinkB=5,
fc="k", ec="k",
connectionstyle="arc3,rad=-0.05",
),
axs = (plt.figure(figsize=(4 * ncol, 1 + nrow))
.add_gridspec(1 + nrow, ncol,
wspace=.5, left=.1, right=.9, bottom=0, top=1).subplots())
for ax in axs.flat:
ax.set_axis_off()
for ax in axs[0, :]:
ax.text(0, .5, "arrowstyle",
transform=ax.transAxes, size="large", color="tab:blue",
horizontalalignment="center", verticalalignment="center")
ax.text(.5, .5, "default parameters",
transform=ax.transAxes,
horizontalalignment="left", verticalalignment="center")
for ax, (stylename, stylecls) in zip(axs[1:, :].T.flat, styles.items()):
l, = ax.plot(.35, .5, "ok", transform=ax.transAxes)
ax.annotate(stylename, (.35, .5), (0, .5),
xycoords="axes fraction", textcoords="axes fraction",
size="large", color="tab:blue",
horizontalalignment="center", verticalalignment="center",
arrowprops=dict(
arrowstyle=stylename, connectionstyle="arc3,rad=-0.05",
color="k", shrinkA=5, shrinkB=5, patchB=l,
),
bbox=dict(boxstyle="square", fc="w"))
ax.text(.5, .5,
str(inspect.signature(stylecls))[1:-1].replace(", ", "\n"),
transform=ax.transAxes,
horizontalalignment="left", verticalalignment="center")

plt.show()

Expand Down