1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| from matplotlib.path import Path
def custom_box_style(x0, y0, width, height, mutation_size, mutation_aspect=1): """ Given the location and size of the box, return the path of the box around it.
- *x0*, *y0*, *width*, *height* : location and size of the box - *mutation_size* : a reference scale for the mutation. - *aspect_ratio* : aspect-ration for the mutation. """
mypad = 0.3 pad = mutation_size * mypad
width = width + 2 * pad height = height + 2 * pad
x0, y0 = x0 - pad, y0 - pad x1, y1 = x0 + width, y0 + height
cp = [(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0-pad, (y0+y1)/2.), (x0, y0), (x0, y0)]
com = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY]
path = Path(cp, com)
return path
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(3, 3)) ax.text(0.5, 0.5, "Test", size=30, va="center", ha="center", bbox=dict(boxstyle=custom_box_style, alpha=0.2))
plt.show()
|