FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Show box/arrowstyle parameters in reference examples. by anntzer · Pull Request #20538 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
33 changes: 22 additions & 11 deletions examples/shapes_and_collections/fancybox_demo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL