Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d7e050b

Browse filesBrowse files
authored
Merge pull request #24596 from ckcherry23/ellipse-annotation
ENH: Add ellipse class for annotation box styles
2 parents 5df9e3c + f81fc12 commit d7e050b
Copy full SHA for d7e050b

File tree

Expand file treeCollapse file tree

5 files changed

+47
-1
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+47
-1
lines changed

‎doc/missing-references.json

Copy file name to clipboardExpand all lines: doc/missing-references.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@
367367
"matplotlib.patches.BoxStyle._Base": [
368368
"lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.Circle:1",
369369
"lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.DArrow:1",
370+
"lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.Ellipse:1",
370371
"lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.LArrow:1",
371372
"lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.Round4:1",
372373
"lib/matplotlib/patches.py:docstring of matplotlib.patches.BoxStyle.Round:1",
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
``ellipse`` boxstyle option for annotations
2+
-------------------------------------------
3+
4+
The ``'ellipse'`` option for boxstyle can now be used to create annotations
5+
with an elliptical outline. It can be used as a closed curve shape for
6+
longer texts instead of the ``'circle'`` boxstyle which can get quite big.
7+
8+
.. plot::
9+
:include-source: true
10+
11+
import matplotlib.pyplot as plt
12+
fig, ax = plt.subplots(figsize=(5, 5))
13+
t = ax.text(0.5, 0.5, "elliptical box",
14+
ha="center", size=15,
15+
bbox=dict(boxstyle="ellipse,pad=0.3"))

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+30-1Lines changed: 30 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,35 @@ 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+
"""
2346+
An elliptical box.
2347+
2348+
.. versionadded:: 3.7
2349+
"""
2350+
2351+
def __init__(self, pad=0.3):
2352+
"""
2353+
Parameters
2354+
----------
2355+
pad : float, default: 0.3
2356+
The amount of padding around the original box.
2357+
"""
2358+
self.pad = pad
2359+
2360+
def __call__(self, x0, y0, width, height, mutation_size):
2361+
pad = mutation_size * self.pad
2362+
width, height = width + 2 * pad, height + 2 * pad
2363+
# boundary of the padded box
2364+
x0, y0 = x0 - pad, y0 - pad
2365+
a = width / math.sqrt(2)
2366+
b = height / math.sqrt(2)
2367+
trans = Affine2D().scale(a, b).translate(x0 + width / 2,
2368+
y0 + height / 2)
2369+
return trans.transform_path(Path.unit_circle())
23412370

23422371
@_register_style(_style_list)
23432372
class LArrow:
Loading

‎tutorials/text/annotations.py

Copy file name to clipboardExpand all lines: tutorials/text/annotations.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
# ========== ============== ==========================
194194
# Circle ``circle`` pad=0.3
195195
# DArrow ``darrow`` pad=0.3
196+
# Ellipse ``ellipse`` pad=0.3
196197
# LArrow ``larrow`` pad=0.3
197198
# RArrow ``rarrow`` pad=0.3
198199
# Round ``round`` pad=0.3,rounding_size=None

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.