25
25
# ``bbox=dict(boxstyle=custom_box_style, ...)`` to `.Axes.text`.
26
26
27
27
28
- def custom_box_style (x0 , y0 , width , height , mutation_size , mutation_aspect = 1 ):
28
+ def custom_box_style (x0 , y0 , width , height , mutation_size ):
29
29
"""
30
30
Given the location and size of the box, return the path of the box around
31
31
it.
@@ -38,11 +38,7 @@ def custom_box_style(x0, y0, width, height, mutation_size, mutation_aspect=1):
38
38
Box location and size.
39
39
mutation_size : float
40
40
Mutation reference scale, typically the text font size.
41
- mutation_aspect
42
- Mutation aspect ratio.
43
41
"""
44
- # We ignore mutation_aspect. This is okay in general.
45
-
46
42
# padding
47
43
mypad = 0.3
48
44
pad = mutation_size * mypad
@@ -66,19 +62,17 @@ def custom_box_style(x0, y0, width, height, mutation_size, mutation_aspect=1):
66
62
67
63
68
64
###############################################################################
69
- # Alternatively, custom box styles can be implemented as subclasses of
70
- # ``matplotlib.patches.BoxStyle._Base``, by overriding the ``transmute``
71
- # method, as demonstrated below.
65
+ # Likewise, custom box styles can be implemented as classes that implement
66
+ # ``__call__``.
72
67
#
73
- # The subclass can then be registered into the ``BoxStyle._style_list`` dict,
68
+ # The classes can then be registered into the ``BoxStyle._style_list`` dict,
74
69
# which allows specifying the box style as a string,
75
70
# ``bbox=dict(boxstyle="registered_name,param=value,...", ...)``.
76
- #
77
- # Note that this approach relies on internal APIs and is therefore not
71
+ # Note that this registration relies on internal APIs and is therefore not
78
72
# officially supported.
79
73
80
74
81
- class MyStyle ( BoxStyle . _Base ) :
75
+ class MyStyle :
82
76
"""A simple box."""
83
77
84
78
def __init__ (self , pad = 0.3 ):
@@ -93,7 +87,7 @@ def __init__(self, pad=0.3):
93
87
self .pad = pad
94
88
super ().__init__ ()
95
89
96
- def transmute (self , x0 , y0 , width , height , mutation_size ):
90
+ def __call__ (self , x0 , y0 , width , height , mutation_size ):
97
91
"""
98
92
Given the location and size of the box, return the path of the box
99
93
around it.
@@ -106,14 +100,6 @@ def transmute(self, x0, y0, width, height, mutation_size):
106
100
Box location and size.
107
101
mutation_size : float
108
102
Reference scale for the mutation, typically the text font size.
109
-
110
- Notes
111
- -----
112
- Unlike when defining the box style as a function (as in
113
- `custom_box_style`), here there is no *mutation_aspect* parameter.
114
- Matplotlib will first squeeze the box's y-axis by *mutation_aspect*
115
- before calling the `transmute` method, and then later reexpand the
116
- y-axis by the same amount.
117
103
"""
118
104
# padding
119
105
pad = mutation_size * self .pad
0 commit comments