@@ -2166,22 +2166,32 @@ def draw_bbox(bbox, renderer, color='k', trans=None):
2166
2166
r .draw (renderer )
2167
2167
2168
2168
2169
- def _simpleprint_styles (_styles ):
2170
- """
2171
- A helper function for the _Style class. Given the dictionary of
2172
- {stylename: styleclass}, return a string rep of the list of keys.
2173
- Used to update the documentation.
2174
- """
2175
- return "[{}]" .format ("|" .join (map (" '{}' " .format , _styles )))
2176
-
2177
-
2178
2169
class _Style :
2179
2170
"""
2180
2171
A base class for the Styles. It is meant to be a container class,
2181
2172
where actual styles are declared as subclass of it, and it
2182
2173
provides some helper functions.
2183
2174
"""
2184
2175
2176
+ def __init_subclass__ (cls ):
2177
+ # Automatically perform docstring interpolation on the subclasses:
2178
+ # This allows listing the supported styles via
2179
+ # - %(BoxStyle:table)s
2180
+ # - %(ConnectionStyle:table)s
2181
+ # - %(ArrowStyle:table)s
2182
+ # and additionally adding .. ACCEPTS: blocks via
2183
+ # - %(BoxStyle:table_and_accepts)s
2184
+ # - %(ConnectionStyle:table_and_accepts)s
2185
+ # - %(ArrowStyle:table_and_accepts)s
2186
+ _docstring .interpd .update ({
2187
+ f"{ cls .__name__ } :table" : cls .pprint_styles (),
2188
+ f"{ cls .__name__ } :table_and_accepts" : (
2189
+ cls .pprint_styles ()
2190
+ + "\n \n .. ACCEPTS: ["
2191
+ + "|" .join (map (" '{}' " .format , cls ._style_list ))
2192
+ + "]" )
2193
+ })
2194
+
2185
2195
def __new__ (cls , stylename , ** kwargs ):
2186
2196
"""Return the instance of the subclass with the given style name."""
2187
2197
# The "class" should have the _style_list attribute, which is a mapping
@@ -2226,7 +2236,6 @@ def pprint_styles(cls):
2226
2236
* [' ' .join (cell .ljust (cl ) for cell , cl in zip (row , col_len ))
2227
2237
for row in table [1 :]],
2228
2238
table_formatstr ,
2229
- '' ,
2230
2239
])
2231
2240
return textwrap .indent (rst_table , prefix = ' ' * 4 )
2232
2241
@@ -2247,6 +2256,7 @@ def _register_style(style_list, cls=None, *, name=None):
2247
2256
return cls
2248
2257
2249
2258
2259
+ @_docstring .dedent_interpd
2250
2260
class BoxStyle (_Style ):
2251
2261
"""
2252
2262
`BoxStyle` is a container class which defines several
@@ -2266,7 +2276,7 @@ class BoxStyle(_Style):
2266
2276
2267
2277
The following boxstyle classes are defined.
2268
2278
2269
- %(AvailableBoxstyles )s
2279
+ %(BoxStyle:table )s
2270
2280
2271
2281
An instance of a boxstyle class is a callable object, with the signature ::
2272
2282
@@ -2624,6 +2634,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
2624
2634
return Path (saw_vertices , codes )
2625
2635
2626
2636
2637
+ @_docstring .dedent_interpd
2627
2638
class ConnectionStyle (_Style ):
2628
2639
"""
2629
2640
`ConnectionStyle` is a container class which defines
@@ -2644,7 +2655,7 @@ class ConnectionStyle(_Style):
2644
2655
2645
2656
The following classes are defined
2646
2657
2647
- %(AvailableConnectorstyles )s
2658
+ %(ConnectionStyle:table )s
2648
2659
2649
2660
An instance of any connection style class is an callable object,
2650
2661
whose call signature is::
@@ -3060,6 +3071,7 @@ def _point_along_a_line(x0, y0, x1, y1, d):
3060
3071
return x2 , y2
3061
3072
3062
3073
3074
+ @_docstring .dedent_interpd
3063
3075
class ArrowStyle (_Style ):
3064
3076
"""
3065
3077
`ArrowStyle` is a container class which defines several
@@ -3080,7 +3092,7 @@ class ArrowStyle(_Style):
3080
3092
3081
3093
The following classes are defined
3082
3094
3083
- %(AvailableArrowstyles )s
3095
+ %(ArrowStyle:table )s
3084
3096
3085
3097
An instance of any arrow style class is a callable object,
3086
3098
whose call signature is::
@@ -3810,17 +3822,6 @@ def transmute(self, path, mutation_size, linewidth):
3810
3822
return path , True
3811
3823
3812
3824
3813
- _docstring .interpd .update (
3814
- AvailableBoxstyles = BoxStyle .pprint_styles (),
3815
- ListBoxstyles = _simpleprint_styles (BoxStyle ._style_list ),
3816
- AvailableArrowstyles = ArrowStyle .pprint_styles (),
3817
- AvailableConnectorstyles = ConnectionStyle .pprint_styles (),
3818
- )
3819
- _docstring .dedent_interpd (BoxStyle )
3820
- _docstring .dedent_interpd (ArrowStyle )
3821
- _docstring .dedent_interpd (ConnectionStyle )
3822
-
3823
-
3824
3825
class FancyBboxPatch (Patch ):
3825
3826
"""
3826
3827
A fancy box around a rectangle with lower left at *xy* = (*x*, *y*)
@@ -3865,7 +3866,7 @@ def __init__(self, xy, width, height,
3865
3866
3866
3867
The following box styles are available:
3867
3868
3868
- %(AvailableBoxstyles )s
3869
+ %(BoxStyle:table )s
3869
3870
3870
3871
mutation_scale : float, default: 1
3871
3872
Scaling factor applied to the attributes of the box style
@@ -3911,9 +3912,8 @@ def __init__(self, xy, width, height,
3911
3912
@_docstring .dedent_interpd
3912
3913
def set_boxstyle (self , boxstyle = None , ** kwargs ):
3913
3914
"""
3914
- Set the box style.
3915
+ Set the box style, possibly with further attributes .
3915
3916
3916
- Most box styles can be further configured using attributes.
3917
3917
Attributes from the previous box style are not reused.
3918
3918
3919
3919
Without argument (or with ``boxstyle=None``), the available box styles
@@ -3922,17 +3922,14 @@ def set_boxstyle(self, boxstyle=None, **kwargs):
3922
3922
Parameters
3923
3923
----------
3924
3924
boxstyle : str or `matplotlib.patches.BoxStyle`
3925
- The style of the fancy box. This can either be a `.BoxStyle`
3926
- instance or a string of the style name and optionally comma
3927
- separated attributes (e.g. "Round, pad=0.2"). This string is
3928
- passed to `.BoxStyle` to construct a `.BoxStyle` object. See
3929
- there for a full documentation.
3925
+ The style of the box: either a `.BoxStyle` instance, or a string,
3926
+ which is the style name and optionally comma separated attributes
3927
+ (e.g. "Round,pad=0.2"). Such a string is used to construct a
3928
+ `.BoxStyle` object, as documented in that class.
3930
3929
3931
3930
The following box styles are available:
3932
3931
3933
- %(AvailableBoxstyles)s
3934
-
3935
- .. ACCEPTS: %(ListBoxstyles)s
3932
+ %(BoxStyle:table_and_accepts)s
3936
3933
3937
3934
**kwargs
3938
3935
Additional attributes for the box style. See the table above for
@@ -3942,17 +3939,20 @@ def set_boxstyle(self, boxstyle=None, **kwargs):
3942
3939
--------
3943
3940
::
3944
3941
3945
- set_boxstyle("round ,pad=0.2")
3942
+ set_boxstyle("Round ,pad=0.2")
3946
3943
set_boxstyle("round", pad=0.2)
3947
-
3948
3944
"""
3949
3945
if boxstyle is None :
3950
3946
return BoxStyle .pprint_styles ()
3951
3947
self ._bbox_transmuter = (
3952
- BoxStyle (boxstyle , ** kwargs ) if isinstance ( boxstyle , str )
3953
- else boxstyle )
3948
+ BoxStyle (boxstyle , ** kwargs )
3949
+ if isinstance ( boxstyle , str ) else boxstyle )
3954
3950
self .stale = True
3955
3951
3952
+ def get_boxstyle (self ):
3953
+ """Return the boxstyle object."""
3954
+ return self ._bbox_transmuter
3955
+
3956
3956
def set_mutation_scale (self , scale ):
3957
3957
"""
3958
3958
Set the mutation scale.
@@ -3984,10 +3984,6 @@ def get_mutation_aspect(self):
3984
3984
return (self ._mutation_aspect if self ._mutation_aspect is not None
3985
3985
else 1 ) # backcompat.
3986
3986
3987
- def get_boxstyle (self ):
3988
- """Return the boxstyle object."""
3989
- return self ._bbox_transmuter
3990
-
3991
3987
def get_path (self ):
3992
3988
"""Return the mutated path of the rectangle."""
3993
3989
boxstyle = self .get_boxstyle ()
@@ -4163,7 +4159,7 @@ def __init__(self, posA=None, posB=None, path=None,
4163
4159
meant to be scaled with the *mutation_scale*. The following arrow
4164
4160
styles are available:
4165
4161
4166
- %(AvailableArrowstyles )s
4162
+ %(ArrowStyle:table )s
4167
4163
4168
4164
connectionstyle : str or `.ConnectionStyle` or None, optional, \
4169
4165
default: 'arc3'
@@ -4172,7 +4168,7 @@ def __init__(self, posA=None, posB=None, path=None,
4172
4168
names, with optional comma-separated attributes. The following
4173
4169
connection styles are available:
4174
4170
4175
- %(AvailableConnectorstyles )s
4171
+ %(ConnectionStyle:table )s
4176
4172
4177
4173
patchA, patchB : `.Patch`, default: None
4178
4174
Head and tail patches, respectively.
@@ -4269,34 +4265,44 @@ def set_patchB(self, patchB):
4269
4265
self .patchB = patchB
4270
4266
self .stale = True
4271
4267
4272
- def set_connectionstyle (self , connectionstyle , ** kwargs ):
4268
+ @_docstring .dedent_interpd
4269
+ def set_connectionstyle (self , connectionstyle = None , ** kwargs ):
4273
4270
"""
4274
- Set the connection style. Old attributes are forgotten.
4271
+ Set the connection style, possibly with further attributes.
4272
+
4273
+ Attributes from the previous connection style are not reused.
4274
+
4275
+ Without argument (or with ``connectionstyle=None``), the available box
4276
+ styles are returned as a human-readable string.
4275
4277
4276
4278
Parameters
4277
4279
----------
4278
- connectionstyle : str or `.ConnectionStyle` or None, optional
4279
- Can be a string with connectionstyle name with
4280
- optional comma-separated attributes, e.g.::
4280
+ connectionstyle : str or `matplotlib.patches.ConnectionStyle`
4281
+ The style of the connection: either a `.ConnectionStyle` instance,
4282
+ or a string, which is the style name and optionally comma separated
4283
+ attributes (e.g. "Arc,armA=30,rad=10"). Such a string is used to
4284
+ construct a `.ConnectionStyle` object, as documented in that class.
4281
4285
4282
- set_connectionstyle("arc,angleA=0,armA=30,rad=10")
4286
+ The following connection styles are available:
4283
4287
4284
- Alternatively, the attributes can be provided as keywords, e.g.::
4288
+ %(ConnectionStyle:table_and_accepts)s
4285
4289
4286
- set_connectionstyle("arc", angleA=0,armA=30,rad=10)
4290
+ **kwargs
4291
+ Additional attributes for the connection style. See the table above
4292
+ for supported parameters.
4287
4293
4288
- Without any arguments (or with ``connectionstyle=None``), return
4289
- available styles as a list of strings.
4290
- """
4294
+ Examples
4295
+ --------
4296
+ ::
4291
4297
4298
+ set_connectionstyle("Arc,armA=30,rad=10")
4299
+ set_connectionstyle("arc", armA=30, rad=10)
4300
+ """
4292
4301
if connectionstyle is None :
4293
4302
return ConnectionStyle .pprint_styles ()
4294
-
4295
- if (isinstance (connectionstyle , ConnectionStyle ._Base ) or
4296
- callable (connectionstyle )):
4297
- self ._connector = connectionstyle
4298
- else :
4299
- self ._connector = ConnectionStyle (connectionstyle , ** kwargs )
4303
+ self ._connector = (
4304
+ ConnectionStyle (connectionstyle , ** kwargs )
4305
+ if isinstance (connectionstyle , str ) else connectionstyle )
4300
4306
self .stale = True
4301
4307
4302
4308
def get_connectionstyle (self ):
@@ -4305,31 +4311,41 @@ def get_connectionstyle(self):
4305
4311
4306
4312
def set_arrowstyle (self , arrowstyle = None , ** kwargs ):
4307
4313
"""
4308
- Set the arrow style. Old attributes are forgotten. Without arguments
4309
- (or with ``arrowstyle=None``) returns available box styles as a list of
4310
- strings.
4314
+ Set the arrow style, possibly with further attributes.
4315
+
4316
+ Attributes from the previous arrow style are not reused.
4317
+
4318
+ Without argument (or with ``arrowstyle=None``), the available box
4319
+ styles are returned as a human-readable string.
4311
4320
4312
4321
Parameters
4313
4322
----------
4314
- arrowstyle : None or ArrowStyle or str, default: None
4315
- Can be a string with arrowstyle name with optional comma-separated
4316
- attributes, e.g.::
4323
+ arrowstyle : str or `matplotlib.patches.ArrowStyle`
4324
+ The style of the arrow: either a `.ArrowStyle` instance, or a
4325
+ string, which is the style name and optionally comma separated
4326
+ attributes (e.g. "Fancy,head_length=0.2"). Such a string is used to
4327
+ construct a `.ArrowStyle` object, as documented in that class.
4317
4328
4318
- set_arrowstyle("Fancy,head_length=0.2")
4329
+ The following arrow styles are available:
4319
4330
4320
- Alternatively attributes can be provided as keywords, e.g.::
4331
+ %(ArrowStyle:table_and_accepts)s
4321
4332
4322
- set_arrowstyle("fancy", head_length=0.2)
4333
+ **kwargs
4334
+ Additional attributes for the arrow style. See the table above for
4335
+ supported parameters.
4323
4336
4324
- """
4337
+ Examples
4338
+ --------
4339
+ ::
4325
4340
4341
+ set_arrowstyle("Fancy,head_length=0.2")
4342
+ set_arrowstyle("fancy", head_length=0.2)
4343
+ """
4326
4344
if arrowstyle is None :
4327
4345
return ArrowStyle .pprint_styles ()
4328
-
4329
- if isinstance (arrowstyle , ArrowStyle ._Base ):
4330
- self ._arrow_transmuter = arrowstyle
4331
- else :
4332
- self ._arrow_transmuter = ArrowStyle (arrowstyle , ** kwargs )
4346
+ self ._arrow_transmuter = (
4347
+ ArrowStyle (arrowstyle , ** kwargs )
4348
+ if isinstance (arrowstyle , str ) else arrowstyle )
4333
4349
self .stale = True
4334
4350
4335
4351
def get_arrowstyle (self ):
0 commit comments