@@ -2179,22 +2179,32 @@ def draw_bbox(bbox, renderer, color='k', trans=None):
2179
2179
r .draw (renderer )
2180
2180
2181
2181
2182
- def _simpleprint_styles (_styles ):
2183
- """
2184
- A helper function for the _Style class. Given the dictionary of
2185
- {stylename: styleclass}, return a string rep of the list of keys.
2186
- Used to update the documentation.
2187
- """
2188
- return "[{}]" .format ("|" .join (map (" '{}' " .format , _styles )))
2189
-
2190
-
2191
2182
class _Style :
2192
2183
"""
2193
2184
A base class for the Styles. It is meant to be a container class,
2194
2185
where actual styles are declared as subclass of it, and it
2195
2186
provides some helper functions.
2196
2187
"""
2197
2188
2189
+ def __init_subclass__ (cls ):
2190
+ # Automatically perform docstring interpolation on the subclasses:
2191
+ # This allows listing the supported styles via
2192
+ # - %(BoxStyle:table)s
2193
+ # - %(ConnectionStyle:table)s
2194
+ # - %(ArrowStyle:table)s
2195
+ # and additionally adding .. ACCEPTS: blocks via
2196
+ # - %(BoxStyle:table_and_accepts)s
2197
+ # - %(ConnectionStyle:table_and_accepts)s
2198
+ # - %(ArrowStyle:table_and_accepts)s
2199
+ _docstring .interpd .update ({
2200
+ f"{ cls .__name__ } :table" : cls .pprint_styles (),
2201
+ f"{ cls .__name__ } :table_and_accepts" : (
2202
+ cls .pprint_styles ()
2203
+ + "\n \n .. ACCEPTS: ["
2204
+ + "|" .join (map (" '{}' " .format , cls ._style_list ))
2205
+ + "]" )
2206
+ })
2207
+
2198
2208
def __new__ (cls , stylename , ** kwargs ):
2199
2209
"""Return the instance of the subclass with the given style name."""
2200
2210
# The "class" should have the _style_list attribute, which is a mapping
@@ -2239,7 +2249,6 @@ def pprint_styles(cls):
2239
2249
* [' ' .join (cell .ljust (cl ) for cell , cl in zip (row , col_len ))
2240
2250
for row in table [1 :]],
2241
2251
table_formatstr ,
2242
- '' ,
2243
2252
])
2244
2253
return textwrap .indent (rst_table , prefix = ' ' * 4 )
2245
2254
@@ -2260,6 +2269,7 @@ def _register_style(style_list, cls=None, *, name=None):
2260
2269
return cls
2261
2270
2262
2271
2272
+ @_docstring .dedent_interpd
2263
2273
class BoxStyle (_Style ):
2264
2274
"""
2265
2275
`BoxStyle` is a container class which defines several
@@ -2279,7 +2289,7 @@ class BoxStyle(_Style):
2279
2289
2280
2290
The following boxstyle classes are defined.
2281
2291
2282
- %(AvailableBoxstyles )s
2292
+ %(BoxStyle:table )s
2283
2293
2284
2294
An instance of a boxstyle class is a callable object, with the signature ::
2285
2295
@@ -2637,6 +2647,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
2637
2647
return Path (saw_vertices , codes )
2638
2648
2639
2649
2650
+ @_docstring .dedent_interpd
2640
2651
class ConnectionStyle (_Style ):
2641
2652
"""
2642
2653
`ConnectionStyle` is a container class which defines
@@ -2657,7 +2668,7 @@ class ConnectionStyle(_Style):
2657
2668
2658
2669
The following classes are defined
2659
2670
2660
- %(AvailableConnectorstyles )s
2671
+ %(ConnectionStyle:table )s
2661
2672
2662
2673
An instance of any connection style class is an callable object,
2663
2674
whose call signature is::
@@ -3073,6 +3084,7 @@ def _point_along_a_line(x0, y0, x1, y1, d):
3073
3084
return x2 , y2
3074
3085
3075
3086
3087
+ @_docstring .dedent_interpd
3076
3088
class ArrowStyle (_Style ):
3077
3089
"""
3078
3090
`ArrowStyle` is a container class which defines several
@@ -3093,7 +3105,7 @@ class ArrowStyle(_Style):
3093
3105
3094
3106
The following classes are defined
3095
3107
3096
- %(AvailableArrowstyles )s
3108
+ %(ArrowStyle:table )s
3097
3109
3098
3110
An instance of any arrow style class is a callable object,
3099
3111
whose call signature is::
@@ -3823,17 +3835,6 @@ def transmute(self, path, mutation_size, linewidth):
3823
3835
return path , True
3824
3836
3825
3837
3826
- _docstring .interpd .update (
3827
- AvailableBoxstyles = BoxStyle .pprint_styles (),
3828
- ListBoxstyles = _simpleprint_styles (BoxStyle ._style_list ),
3829
- AvailableArrowstyles = ArrowStyle .pprint_styles (),
3830
- AvailableConnectorstyles = ConnectionStyle .pprint_styles (),
3831
- )
3832
- _docstring .dedent_interpd (BoxStyle )
3833
- _docstring .dedent_interpd (ArrowStyle )
3834
- _docstring .dedent_interpd (ConnectionStyle )
3835
-
3836
-
3837
3838
class FancyBboxPatch (Patch ):
3838
3839
"""
3839
3840
A fancy box around a rectangle with lower left at *xy* = (*x*, *y*)
@@ -3878,7 +3879,7 @@ def __init__(self, xy, width, height,
3878
3879
3879
3880
The following box styles are available:
3880
3881
3881
- %(AvailableBoxstyles )s
3882
+ %(BoxStyle:table )s
3882
3883
3883
3884
mutation_scale : float, default: 1
3884
3885
Scaling factor applied to the attributes of the box style
@@ -3924,9 +3925,8 @@ def __init__(self, xy, width, height,
3924
3925
@_docstring .dedent_interpd
3925
3926
def set_boxstyle (self , boxstyle = None , ** kwargs ):
3926
3927
"""
3927
- Set the box style.
3928
+ Set the box style, possibly with further attributes .
3928
3929
3929
- Most box styles can be further configured using attributes.
3930
3930
Attributes from the previous box style are not reused.
3931
3931
3932
3932
Without argument (or with ``boxstyle=None``), the available box styles
@@ -3935,17 +3935,14 @@ def set_boxstyle(self, boxstyle=None, **kwargs):
3935
3935
Parameters
3936
3936
----------
3937
3937
boxstyle : str or `matplotlib.patches.BoxStyle`
3938
- The style of the fancy box. This can either be a `.BoxStyle`
3939
- instance or a string of the style name and optionally comma
3940
- separated attributes (e.g. "Round, pad=0.2"). This string is
3941
- passed to `.BoxStyle` to construct a `.BoxStyle` object. See
3942
- there for a full documentation.
3938
+ The style of the box: either a `.BoxStyle` instance, or a string,
3939
+ which is the style name and optionally comma separated attributes
3940
+ (e.g. "Round,pad=0.2"). Such a string is used to construct a
3941
+ `.BoxStyle` object, as documented in that class.
3943
3942
3944
3943
The following box styles are available:
3945
3944
3946
- %(AvailableBoxstyles)s
3947
-
3948
- .. ACCEPTS: %(ListBoxstyles)s
3945
+ %(BoxStyle:table_and_accepts)s
3949
3946
3950
3947
**kwargs
3951
3948
Additional attributes for the box style. See the table above for
@@ -3955,17 +3952,20 @@ def set_boxstyle(self, boxstyle=None, **kwargs):
3955
3952
--------
3956
3953
::
3957
3954
3958
- set_boxstyle("round ,pad=0.2")
3955
+ set_boxstyle("Round ,pad=0.2")
3959
3956
set_boxstyle("round", pad=0.2)
3960
-
3961
3957
"""
3962
3958
if boxstyle is None :
3963
3959
return BoxStyle .pprint_styles ()
3964
3960
self ._bbox_transmuter = (
3965
- BoxStyle (boxstyle , ** kwargs ) if isinstance ( boxstyle , str )
3966
- else boxstyle )
3961
+ BoxStyle (boxstyle , ** kwargs )
3962
+ if isinstance ( boxstyle , str ) else boxstyle )
3967
3963
self .stale = True
3968
3964
3965
+ def get_boxstyle (self ):
3966
+ """Return the boxstyle object."""
3967
+ return self ._bbox_transmuter
3968
+
3969
3969
def set_mutation_scale (self , scale ):
3970
3970
"""
3971
3971
Set the mutation scale.
@@ -3997,10 +3997,6 @@ def get_mutation_aspect(self):
3997
3997
return (self ._mutation_aspect if self ._mutation_aspect is not None
3998
3998
else 1 ) # backcompat.
3999
3999
4000
- def get_boxstyle (self ):
4001
- """Return the boxstyle object."""
4002
- return self ._bbox_transmuter
4003
-
4004
4000
def get_path (self ):
4005
4001
"""Return the mutated path of the rectangle."""
4006
4002
boxstyle = self .get_boxstyle ()
@@ -4176,7 +4172,7 @@ def __init__(self, posA=None, posB=None, path=None,
4176
4172
meant to be scaled with the *mutation_scale*. The following arrow
4177
4173
styles are available:
4178
4174
4179
- %(AvailableArrowstyles )s
4175
+ %(ArrowStyle:table )s
4180
4176
4181
4177
connectionstyle : str or `.ConnectionStyle` or None, optional, \
4182
4178
default: 'arc3'
@@ -4185,7 +4181,7 @@ def __init__(self, posA=None, posB=None, path=None,
4185
4181
names, with optional comma-separated attributes. The following
4186
4182
connection styles are available:
4187
4183
4188
- %(AvailableConnectorstyles )s
4184
+ %(ConnectionStyle:table )s
4189
4185
4190
4186
patchA, patchB : `.Patch`, default: None
4191
4187
Head and tail patches, respectively.
@@ -4282,34 +4278,44 @@ def set_patchB(self, patchB):
4282
4278
self .patchB = patchB
4283
4279
self .stale = True
4284
4280
4285
- def set_connectionstyle (self , connectionstyle , ** kwargs ):
4281
+ @_docstring .dedent_interpd
4282
+ def set_connectionstyle (self , connectionstyle = None , ** kwargs ):
4286
4283
"""
4287
- Set the connection style. Old attributes are forgotten.
4284
+ Set the connection style, possibly with further attributes.
4285
+
4286
+ Attributes from the previous connection style are not reused.
4287
+
4288
+ Without argument (or with ``connectionstyle=None``), the available box
4289
+ styles are returned as a human-readable string.
4288
4290
4289
4291
Parameters
4290
4292
----------
4291
- connectionstyle : str or `.ConnectionStyle` or None, optional
4292
- Can be a string with connectionstyle name with
4293
- optional comma-separated attributes, e.g.::
4293
+ connectionstyle : str or `matplotlib.patches.ConnectionStyle`
4294
+ The style of the connection: either a `.ConnectionStyle` instance,
4295
+ or a string, which is the style name and optionally comma separated
4296
+ attributes (e.g. "Arc,armA=30,rad=10"). Such a string is used to
4297
+ construct a `.ConnectionStyle` object, as documented in that class.
4294
4298
4295
- set_connectionstyle("arc,angleA=0,armA=30,rad=10")
4299
+ The following connection styles are available:
4296
4300
4297
- Alternatively, the attributes can be provided as keywords, e.g.::
4301
+ %(ConnectionStyle:table_and_accepts)s
4298
4302
4299
- set_connectionstyle("arc", angleA=0,armA=30,rad=10)
4303
+ **kwargs
4304
+ Additional attributes for the connection style. See the table above
4305
+ for supported parameters.
4300
4306
4301
- Without any arguments (or with ``connectionstyle=None``), return
4302
- available styles as a list of strings.
4303
- """
4307
+ Examples
4308
+ --------
4309
+ ::
4304
4310
4311
+ set_connectionstyle("Arc,armA=30,rad=10")
4312
+ set_connectionstyle("arc", armA=30, rad=10)
4313
+ """
4305
4314
if connectionstyle is None :
4306
4315
return ConnectionStyle .pprint_styles ()
4307
-
4308
- if (isinstance (connectionstyle , ConnectionStyle ._Base ) or
4309
- callable (connectionstyle )):
4310
- self ._connector = connectionstyle
4311
- else :
4312
- self ._connector = ConnectionStyle (connectionstyle , ** kwargs )
4316
+ self ._connector = (
4317
+ ConnectionStyle (connectionstyle , ** kwargs )
4318
+ if isinstance (connectionstyle , str ) else connectionstyle )
4313
4319
self .stale = True
4314
4320
4315
4321
def get_connectionstyle (self ):
@@ -4318,31 +4324,41 @@ def get_connectionstyle(self):
4318
4324
4319
4325
def set_arrowstyle (self , arrowstyle = None , ** kwargs ):
4320
4326
"""
4321
- Set the arrow style. Old attributes are forgotten. Without arguments
4322
- (or with ``arrowstyle=None``) returns available box styles as a list of
4323
- strings.
4327
+ Set the arrow style, possibly with further attributes.
4328
+
4329
+ Attributes from the previous arrow style are not reused.
4330
+
4331
+ Without argument (or with ``arrowstyle=None``), the available box
4332
+ styles are returned as a human-readable string.
4324
4333
4325
4334
Parameters
4326
4335
----------
4327
- arrowstyle : None or ArrowStyle or str, default: None
4328
- Can be a string with arrowstyle name with optional comma-separated
4329
- attributes, e.g.::
4336
+ arrowstyle : str or `matplotlib.patches.ArrowStyle`
4337
+ The style of the arrow: either a `.ArrowStyle` instance, or a
4338
+ string, which is the style name and optionally comma separated
4339
+ attributes (e.g. "Fancy,head_length=0.2"). Such a string is used to
4340
+ construct a `.ArrowStyle` object, as documented in that class.
4330
4341
4331
- set_arrowstyle("Fancy,head_length=0.2")
4342
+ The following arrow styles are available:
4332
4343
4333
- Alternatively attributes can be provided as keywords, e.g.::
4344
+ %(ArrowStyle:table_and_accepts)s
4334
4345
4335
- set_arrowstyle("fancy", head_length=0.2)
4346
+ **kwargs
4347
+ Additional attributes for the arrow style. See the table above for
4348
+ supported parameters.
4336
4349
4337
- """
4350
+ Examples
4351
+ --------
4352
+ ::
4338
4353
4354
+ set_arrowstyle("Fancy,head_length=0.2")
4355
+ set_arrowstyle("fancy", head_length=0.2)
4356
+ """
4339
4357
if arrowstyle is None :
4340
4358
return ArrowStyle .pprint_styles ()
4341
-
4342
- if isinstance (arrowstyle , ArrowStyle ._Base ):
4343
- self ._arrow_transmuter = arrowstyle
4344
- else :
4345
- self ._arrow_transmuter = ArrowStyle (arrowstyle , ** kwargs )
4359
+ self ._arrow_transmuter = (
4360
+ ArrowStyle (arrowstyle , ** kwargs )
4361
+ if isinstance (arrowstyle , str ) else arrowstyle )
4346
4362
self .stale = True
4347
4363
4348
4364
def get_arrowstyle (self ):
0 commit comments