2525# ``bbox=dict(boxstyle=custom_box_style, ...)`` to `.Axes.text`.
2626
2727
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 ):
2929 """
3030 Given the location and size of the box, return the path of the box around
3131 it.
@@ -38,11 +38,7 @@ def custom_box_style(x0, y0, width, height, mutation_size, mutation_aspect=1):
3838 Box location and size.
3939 mutation_size : float
4040 Mutation reference scale, typically the text font size.
41- mutation_aspect
42- Mutation aspect ratio.
4341 """
44- # We ignore mutation_aspect. This is okay in general.
45-
4642 # padding
4743 mypad = 0.3
4844 pad = mutation_size * mypad
@@ -66,19 +62,17 @@ def custom_box_style(x0, y0, width, height, mutation_size, mutation_aspect=1):
6662
6763
6864###############################################################################
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__``.
7267#
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,
7469# which allows specifying the box style as a string,
7570# ``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
7872# officially supported.
7973
8074
81- class MyStyle ( BoxStyle . _Base ) :
75+ class MyStyle :
8276 """A simple box."""
8377
8478 def __init__ (self , pad = 0.3 ):
@@ -93,7 +87,7 @@ def __init__(self, pad=0.3):
9387 self .pad = pad
9488 super ().__init__ ()
9589
96- def transmute (self , x0 , y0 , width , height , mutation_size ):
90+ def __call__ (self , x0 , y0 , width , height , mutation_size ):
9791 """
9892 Given the location and size of the box, return the path of the box
9993 around it.
@@ -106,14 +100,6 @@ def transmute(self, x0, y0, width, height, mutation_size):
106100 Box location and size.
107101 mutation_size : float
108102 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.
117103 """
118104 # padding
119105 pad = mutation_size * self .pad
0 commit comments