|
9 | 9 | import textwrap |
10 | 10 | from types import SimpleNamespace |
11 | 11 | from collections import namedtuple |
| 12 | +from matplotlib.transforms import Affine2D |
12 | 13 |
|
13 | 14 | import numpy as np |
14 | 15 |
|
@@ -2337,7 +2338,32 @@ def __call__(self, x0, y0, width, height, mutation_size): |
2337 | 2338 | # boundary of the padded box |
2338 | 2339 | x0, y0 = x0 - pad, y0 - pad |
2339 | 2340 | 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 |
2341 | 2367 |
|
2342 | 2368 | @_register_style(_style_list) |
2343 | 2369 | class LArrow: |
|
0 commit comments