Skip to content

Commit 1d28f8f

Browse files
committed
Add ellipse class for annotation box styles
1 parent 5044b59 commit 1d28f8f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

lib/matplotlib/patches.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import textwrap
1010
from types import SimpleNamespace
1111
from collections import namedtuple
12+
from matplotlib.transforms import Affine2D
1213

1314
import numpy as np
1415

@@ -2337,7 +2338,32 @@ def __call__(self, x0, y0, width, height, mutation_size):
23372338
# boundary of the padded box
23382339
x0, y0 = x0 - pad, y0 - pad
23392340
return Path.circle((x0 + width / 2, y0 + height / 2),
2340-
max(width, height) / 2)
2341+
max(width, height) / 2)
2342+
2343+
@_register_style(_style_list)
2344+
class Ellipse:
2345+
"""An elliptical box."""
2346+
2347+
def __init__(self, pad=0.3):
2348+
"""
2349+
Parameters
2350+
----------
2351+
pad : float, default: 0.3
2352+
The amount of padding around the original box.
2353+
"""
2354+
self.pad = pad
2355+
2356+
def __call__(self, x0, y0, width, height, mutation_size):
2357+
pad = mutation_size * self.pad
2358+
width, height = width + 2 * pad, height + 2 * pad
2359+
# boundary of the padded box
2360+
x0, y0 = x0 - pad, y0 - pad
2361+
a = width / math.sqrt(2)
2362+
b = height / math.sqrt(2)
2363+
trans = Affine2D().scale(a, b).translate(x0 + width / 2,
2364+
y0 + height / 2)
2365+
ellipse_path = trans.transform_path(Path.unit_circle())
2366+
return ellipse_path
23412367

23422368
@_register_style(_style_list)
23432369
class LArrow:

0 commit comments

Comments
 (0)