Skip to content

Commit d928c52

Browse files
authored
Merge pull request #15420 from meeseeksmachine/auto-backport-of-pr-15380-on-v3.2.x
Backport PR #15380 on branch v3.2.x (Update docs of BoxStyle)
2 parents 2da3832 + 5667b7b commit d928c52

File tree

1 file changed

+93
-73
lines changed

1 file changed

+93
-73
lines changed

lib/matplotlib/patches.py

Lines changed: 93 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,26 +1909,24 @@ class BoxStyle(_Style):
19091909

19101910
class _Base:
19111911
"""
1912-
:class:`BBoxTransmuterBase` and its derivatives are used to make a
1913-
fancy box around a given rectangle. The :meth:`__call__` method
1914-
returns the :class:`~matplotlib.path.Path` of the fancy box. This
1915-
class is not an artist and actual drawing of the fancy box is done
1916-
by the :class:`FancyBboxPatch` class.
1917-
"""
1912+
Abstract base class for styling of `.FancyBboxPatch`.
19181913
1919-
# The derived classes are required to be able to be initialized
1920-
# w/o arguments, i.e., all its argument (except self) must have
1921-
# the default values.
1914+
This class is not an artist itself. The `__call__` method returns the
1915+
`~matplotlib.path.Path` for outlining the fancy box. The actual drawing
1916+
is handled in `.FancyBboxPatch`.
1917+
1918+
Subclasses may only use parameters with default values in their
1919+
``__init__`` method because they must be able to be initialized
1920+
without arguments.
1921+
1922+
Subclasses must implement the `transmute` method. It receives the
1923+
enclosing rectangle *x0, y0, width, height* as well as the
1924+
*mutation_size*, which scales the outline properties such as padding.
1925+
It returns the outline of the fancy box as `.path.Path`.
1926+
"""
19221927

19231928
def transmute(self, x0, y0, width, height, mutation_size):
1924-
"""
1925-
The transmute method is a very core of the
1926-
:class:`BboxTransmuter` class and must be overridden in the
1927-
subclasses. It receives the location and size of the
1928-
rectangle, and the mutation_size, with which the amount of
1929-
padding and etc. will be scaled. It returns a
1930-
:class:`~matplotlib.path.Path` instance.
1931-
"""
1929+
"""Return the `~.path.Path` outlining the given rectangle."""
19321930
raise NotImplementedError('Derived must override')
19331931

19341932
def __call__(self, x0, y0, width, height, mutation_size,
@@ -1937,9 +1935,18 @@ def __call__(self, x0, y0, width, height, mutation_size,
19371935
Given the location and size of the box, return the path of
19381936
the box around it.
19391937
1940-
- *x0*, *y0*, *width*, *height* : location and size of the box
1941-
- *mutation_size* : a reference scale for the mutation.
1942-
- *aspect_ratio* : aspect-ration for the mutation.
1938+
Parameters
1939+
----------
1940+
x0, y0, width, height : float
1941+
Location and size of the box.
1942+
mutation_size : float
1943+
A reference scale for the mutation.
1944+
aspect_ratio : float, default: 1
1945+
Aspect-ratio for the mutation.
1946+
1947+
Returns
1948+
-------
1949+
path : `~matplotlib.path.Path`
19431950
"""
19441951
# The __call__ method is a thin wrapper around the transmute method
19451952
# and takes care of the aspect.
@@ -1959,15 +1966,14 @@ def __call__(self, x0, y0, width, height, mutation_size,
19591966
@_register_style(_style_list)
19601967
class Square(_Base):
19611968
"""
1962-
A simple square box.
1963-
"""
1969+
A square box.
19641970
1971+
Parameters
1972+
----------
1973+
pad : float, default: 0.3
1974+
The amount of padding around the original box.
1975+
"""
19651976
def __init__(self, pad=0.3):
1966-
"""
1967-
Parameters
1968-
----------
1969-
pad : float
1970-
"""
19711977
self.pad = pad
19721978
super().__init__()
19731979

@@ -1987,14 +1993,15 @@ def transmute(self, x0, y0, width, height, mutation_size):
19871993

19881994
@_register_style(_style_list)
19891995
class Circle(_Base):
1990-
"""A simple circle box."""
1996+
"""
1997+
A circular box.
1998+
1999+
Parameters
2000+
----------
2001+
pad : float, default: 0.3
2002+
The amount of padding around the original box.
2003+
"""
19912004
def __init__(self, pad=0.3):
1992-
"""
1993-
Parameters
1994-
----------
1995-
pad : float
1996-
The amount of padding around the original box.
1997-
"""
19982005
self.pad = pad
19992006
super().__init__()
20002007

@@ -2010,7 +2017,12 @@ def transmute(self, x0, y0, width, height, mutation_size):
20102017
@_register_style(_style_list)
20112018
class LArrow(_Base):
20122019
"""
2013-
(left) Arrow Box
2020+
A box in the shape of a left-pointing arrow.
2021+
2022+
Parameters
2023+
----------
2024+
pad : float, default: 0.3
2025+
The amount of padding around the original box.
20142026
"""
20152027
def __init__(self, pad=0.3):
20162028
self.pad = pad
@@ -2048,9 +2060,13 @@ def transmute(self, x0, y0, width, height, mutation_size):
20482060
@_register_style(_style_list)
20492061
class RArrow(LArrow):
20502062
"""
2051-
(right) Arrow Box
2052-
"""
2063+
A box in the shape of a right-pointing arrow.
20532064
2065+
Parameters
2066+
----------
2067+
pad : float, default: 0.3
2068+
The amount of padding around the original box.
2069+
"""
20542070
def __init__(self, pad=0.3):
20552071
super().__init__(pad)
20562072

@@ -2063,7 +2079,12 @@ def transmute(self, x0, y0, width, height, mutation_size):
20632079
@_register_style(_style_list)
20642080
class DArrow(_Base):
20652081
"""
2066-
(Double) Arrow Box
2082+
A box in the shape of a two-way arrow.
2083+
2084+
Parameters
2085+
----------
2086+
pad : float, default: 0.3
2087+
The amount of padding around the original box.
20672088
"""
20682089
# This source is copied from LArrow,
20692090
# modified to add a right arrow to the bbox.
@@ -2114,16 +2135,15 @@ def transmute(self, x0, y0, width, height, mutation_size):
21142135
class Round(_Base):
21152136
"""
21162137
A box with round corners.
2117-
"""
21182138
2139+
Parameters
2140+
----------
2141+
pad : float, default: 0.3
2142+
The amount of padding around the original box.
2143+
rounding_size : float, default: *pad*
2144+
Radius of the corners.
2145+
"""
21192146
def __init__(self, pad=0.3, rounding_size=None):
2120-
"""
2121-
*pad*
2122-
amount of padding
2123-
2124-
*rounding_size*
2125-
rounding radius of corners. *pad* if None
2126-
"""
21272147
self.pad = pad
21282148
self.rounding_size = rounding_size
21292149
super().__init__()
@@ -2175,17 +2195,16 @@ def transmute(self, x0, y0, width, height, mutation_size):
21752195
@_register_style(_style_list)
21762196
class Round4(_Base):
21772197
"""
2178-
Another box with round edges.
2179-
"""
2198+
A box with rounded edges.
21802199
2200+
Parameters
2201+
----------
2202+
pad : float, default: 0.3
2203+
The amount of padding around the original box.
2204+
rounding_size : float, default: *pad*/2
2205+
Rounding of edges.
2206+
"""
21812207
def __init__(self, pad=0.3, rounding_size=None):
2182-
"""
2183-
*pad*
2184-
amount of padding
2185-
2186-
*rounding_size*
2187-
rounding size of edges. *pad* if None
2188-
"""
21892208
self.pad = pad
21902209
self.rounding_size = rounding_size
21912210
super().__init__()
@@ -2228,17 +2247,16 @@ def transmute(self, x0, y0, width, height, mutation_size):
22282247
@_register_style(_style_list)
22292248
class Sawtooth(_Base):
22302249
"""
2231-
A sawtooth box.
2232-
"""
2250+
A box with a sawtooth outline.
22332251
2252+
Parameters
2253+
----------
2254+
pad : float, default: 0.3
2255+
The amount of padding around the original box.
2256+
tooth_size : float, default: *pad*/2
2257+
Size of the sawtooth.
2258+
"""
22342259
def __init__(self, pad=0.3, tooth_size=None):
2235-
"""
2236-
*pad*
2237-
amount of padding
2238-
2239-
*tooth_size*
2240-
size of the sawtooth. pad* if None
2241-
"""
22422260
self.pad = pad
22432261
self.tooth_size = tooth_size
22442262
super().__init__()
@@ -2325,15 +2343,17 @@ def transmute(self, x0, y0, width, height, mutation_size):
23252343

23262344
@_register_style(_style_list)
23272345
class Roundtooth(Sawtooth):
2328-
"""A rounded tooth box."""
2329-
def __init__(self, pad=0.3, tooth_size=None):
2330-
"""
2331-
*pad*
2332-
amount of padding
2346+
"""
2347+
A box with a rounded sawtooth outline.
23332348
2334-
*tooth_size*
2335-
size of the sawtooth. pad* if None
2336-
"""
2349+
Parameters
2350+
----------
2351+
pad : float, default: 0.3
2352+
The amount of padding around the original box.
2353+
tooth_size : float, default: *pad*/2
2354+
Size of the sawtooth.
2355+
"""
2356+
def __init__(self, pad=0.3, tooth_size=None):
23372357
super().__init__(pad, tooth_size)
23382358

23392359
def transmute(self, x0, y0, width, height, mutation_size):
@@ -2364,7 +2384,7 @@ class FancyBboxPatch(Patch):
23642384
23652385
`.FancyBboxPatch` is similar to `.Rectangle`, but it draws a fancy box
23662386
around the rectangle. The transformation of the rectangle box to the
2367-
fancy box is delegated to the `.BoxTransmuterBase` and its derived classes.
2387+
fancy box is delegated to the style classes defined in `.BoxStyle`.
23682388
"""
23692389

23702390
_edge_default = True

0 commit comments

Comments
 (0)