1
1
"""
2
- Defines classes for path effects. The path effects are supported in
3
- :class:`~matplotlib.text.Text`, :class:`~matplotlib.lines.Line2D`
4
- and :class:`~matplotlib.patches.Patch`.
2
+ Defines classes for path effects. The path effects are supported in `~.Text`,
3
+ `~.Line2D` and `~.Patch`.
4
+
5
+ .. seealso::
6
+ :doc:`/tutorials/advanced/patheffects_guide`
5
7
"""
6
8
7
9
from matplotlib .backend_bases import RendererBase
@@ -159,7 +161,35 @@ class Normal(AbstractPathEffect):
159
161
The Normal PathEffect's sole purpose is to draw the original artist with
160
162
no special path effect.
161
163
"""
162
- pass
164
+
165
+
166
+ def _subclass_with_normal (effect_class ):
167
+ """
168
+ Create a PathEffect class combining *effect_class* and a normal draw.
169
+ """
170
+
171
+ class withEffect (effect_class ):
172
+ def draw_path (self , renderer , gc , tpath , affine , rgbFace ):
173
+ super ().draw_path (renderer , gc , tpath , affine , rgbFace )
174
+ renderer .draw_path (gc , tpath , affine , rgbFace )
175
+
176
+ withEffect .__name__ = f"with{ effect_class .__name__ } "
177
+ withEffect .__doc__ = f"""
178
+ A shortcut PathEffect for applying `.{ effect_class .__name__ } ` and then
179
+ drawing the original Artist.
180
+
181
+ With this class you can use ::
182
+
183
+ artist.set_path_effects([path_effects.with{ effect_class .__name__ } ()])
184
+
185
+ as a shortcut for ::
186
+
187
+ artist.set_path_effects([path_effects.{ effect_class .__name__ } (),
188
+ path_effects.Normal()])
189
+ """
190
+ # Docstring inheritance doesn't work for locally-defined subclasses.
191
+ withEffect .draw_path .__doc__ = effect_class .draw_path .__doc__
192
+ return withEffect
163
193
164
194
165
195
class Stroke (AbstractPathEffect ):
@@ -184,15 +214,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
184
214
gc0 .restore ()
185
215
186
216
187
- class withStroke (Stroke ):
188
- """
189
- Adds a simple :class:`Stroke` and then draws the
190
- original Artist to avoid needing to call :class:`Normal`.
191
- """
192
-
193
- def draw_path (self , renderer , gc , tpath , affine , rgbFace ):
194
- Stroke .draw_path (self , renderer , gc , tpath , affine , rgbFace )
195
- renderer .draw_path (gc , tpath , affine , rgbFace )
217
+ withStroke = _subclass_with_normal (effect_class = Stroke )
196
218
197
219
198
220
class SimplePatchShadow (AbstractPathEffect ):
@@ -261,15 +283,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
261
283
gc0 .restore ()
262
284
263
285
264
- class withSimplePatchShadow (SimplePatchShadow ):
265
- """
266
- Adds a simple :class:`SimplePatchShadow` and then draws the
267
- original Artist to avoid needing to call :class:`Normal`.
268
- """
269
-
270
- def draw_path (self , renderer , gc , tpath , affine , rgbFace ):
271
- SimplePatchShadow .draw_path (self , renderer , gc , tpath , affine , rgbFace )
272
- renderer .draw_path (gc , tpath , affine , rgbFace )
286
+ withSimplePatchShadow = _subclass_with_normal (effect_class = SimplePatchShadow )
273
287
274
288
275
289
class SimpleLineShadow (AbstractPathEffect ):
0 commit comments