8000 Merge pull request #20493 from anntzer/cleanup-anchored-demos · matplotlib/matplotlib@6abaf1f · GitHub
[go: up one dir, main page]

Skip to content

Commit 6abaf1f

Browse files
authored
Merge pull request #20493 from anntzer/cleanup-anchored-demos
Cleanup AnchoredOffsetbox-related demos.
2 parents bfd3b4e + dfd6da1 commit 6abaf1f

File tree

6 files changed

+267
-374
lines changed

6 files changed

+267
-374
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ per-file-ignores =
102102
tutorials/introductory/pyplot.py: E402, E501
103103
tutorials/introductory/sample_plots.py: E501
104104
tutorials/introductory/usage.py: E501
105-
tutorials/text/annotations.py: E501
105+
tutorials/text/annotations.py: E402, E501
106106
tutorials/text/text_intro.py: E402
107107
tutorials/text/text_props.py: E501
108108
tutorials/text/usetex.py: E501

examples/misc/anchored_artists.py

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,76 +9,43 @@
99
:doc:`/gallery/axes_grid1/simple_anchored_artists`, but it is
1010
implemented using only the matplotlib namespace, without the help
1111
of additional toolkits.
12+
13+
.. redirect-from:: /gallery/userdemo/anchored_box01
14+
.. redirect-from:: /gallery/userdemo/anchored_box02
15+
.. redirect-from:: /gallery/userdemo/anchored_box03
1216
"""
1317

1418
from matplotlib import pyplot as plt
1519
from matplotlib.lines import Line2D
16-
from matplotlib.patches import Ellipse
20+
from matplotlib.patches import Circle, Ellipse
1721
from matplotlib.offsetbox import (
1822
AnchoredOffsetbox, AuxTransformBox, DrawingArea, TextArea, VPacker)
1923

2024

21-
class AnchoredText(AnchoredOffsetbox):
22-
def __init__(self, s, loc, pad=0.4, borderpad=0.5,
23-
prop=None, frameon=True):
24-
self.txt = TextArea(s)
25-
super().__init__(loc, pad=pad, borderpad=borderpad,
26-
child=self.txt, prop=prop, frameon=frameon)
27-
28-
2925
def draw_text(ax):
30-
"""
31-
Draw a text-box anchored to the upper-left corner of the figure.
32-
"""
33-
at = AnchoredText("Figure 1a", loc='upper left', frameon=True)
34-
at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
35-
ax.add_artist(at)
36-
37-
38-
class AnchoredDrawingArea(AnchoredOffsetbox):
39-
def __init__(self, width, height, xdescent, ydescent,
40-
loc, pad=0.4, borderpad=0.5, prop=None, frameon=True):
41-
self.da = DrawingArea(width, height, xdescent, ydescent)
42-
super().__init__(loc, pad=pad, borderpad=borderpad,
43-
child=self.da, prop=None, frameon=frameon)
44-
45-
46-
def draw_circle(ax):
47-
"""
48-
Draw a circle in axis coordinates
49-
"""
50-
from matplotlib.patches import Circle
51-
ada = AnchoredDrawingArea(20, 20, 0, 0,
52-
loc='upper right', pad=0., frameon=False)
53-
p = Circle((10, 10), 10)
54-
ada.da.add_artist(p)
55-
ax.add_artist(ada)
26+
"""Draw a text-box anchored to the upper-left corner of the figure."""
27+
box = AnchoredOffsetbox(child=TextArea("Figure 1a"),
28+
loc="upper left", frameon=True)
29+
box.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
30+
ax.add_artist(box)
5631

5732

58-
class AnchoredEllipse(AnchoredOffsetbox):
59-
def __init__(self, transform, width, height, angle, loc,
60-
pad=0.1, borderpad=0.1, prop=None, frameon=True):
61-
"""
62-
Draw an ellipse the size in data coordinate of the give axes.
63-
64-
pad, borderpad in fraction of the legend font size (or prop)
65-
"""
66-
self._box = AuxTransformBox(transform)
67-
self.ellipse = Ellipse((0, 0), width, height, angle)
68-
self._box.add_artist(self.ellipse)
69-
super().__init__(loc, pad=pad, borderpad=borderpad,
70-
child=self._box, prop=prop, frameon=frameon)
33+
def draw_circles(ax):
34+
"""Draw circles in axes coordinates."""
35+
area = DrawingArea(40, 20, 0, 0)
36+
area.add_artist(Circle((10, 10), 10, fc="tab:blue"))
37+
area.add_artist(Circle((30, 10), 5, fc="tab:red"))
38+
box = AnchoredOffsetbox(
39+
child=area, loc="upper right", pad=0, frameon=False)
40+
ax.add_artist(box)
7141

7242

7343
def draw_ellipse(ax):
74-
"""
75-
Draw an ellipse of width=0.1, height=0.15 in data coordinates
76-
"""
77-
ae = AnchoredEllipse(ax.transData, width=0.1, height=0.15, angle=0.,
78-
loc='lower left', pad=0.5, borderpad=0.4,
79-
frameon=True)
80-
81-
ax.add_artist(ae)
44+
"""Draw an ellipse of width=0.1, height=0.15 in data coordinates."""
45+
aux_tr_box = AuxTransformBox(ax.transData)
46+
aux_tr_box.add_artist(Ellipse((0, 0), width=0.1, height=0.15))
47+
box = AnchoredOffsetbox(child=aux_tr_box, loc="lower left", frameon=True)
48+
ax.add_artist(box)
8249

8350

8451
class AnchoredSizeBar(AnchoredOffsetbox):
@@ -115,11 +82,11 @@ def draw_sizebar(ax):
11582
ax.add_artist(asb)
11683

11784

118-
ax = plt.gca()
119-
ax.set_aspect(1.)
85+
fig, ax = plt.subplots()
86+
ax.set_aspect(1)
12087

12188
draw_text(ax)
122-
draw_circle(ax)
89+
draw_circles(ax)
12390
draw_ellipse(ax)
12491
draw_sizebar(ax)
12592

examples/userdemo/anchored_box01.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples/userdemo/anchored_box02.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/userdemo/anchored_box03.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0