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 ):
@@ -185,15 +215,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
185
215
gc0 .restore ()
186
216
187
217
188
- class withStroke (Stroke ):
189
- """
190
- Adds a simple :class:`Stroke` and then draws the
191
- original Artist to avoid needing to call :class:`Normal`.
192
-
193
- """
194
- def draw_path (self , renderer , gc , tpath , affine , rgbFace ):
195
- Stroke .draw_path (self , renderer , gc , tpath , affine , rgbFace )
196
- renderer .draw_path (gc , tpath , affine , rgbFace )
218
+ withStroke = _subclass_with_normal (effect_class = Stroke )
197
219
198
220
199
221
class SimplePatchShadow (AbstractPathEffect ):
@@ -262,15 +284,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
262
284
gc0 .restore ()
263
285
264
286
265
- class withSimplePatchShadow (SimplePatchShadow ):
266
- """
267
- Adds a simple :class:`SimplePatchShadow` and then draws the
268
- original Artist to avoid needing to call :class:`Normal`.
269
-
270
- """
271
- def draw_path (self , renderer , gc , tpath , affine , rgbFace ):
272
- SimplePatchShadow .draw_path (self , renderer , gc , tpath , affine , rgbFace )
273
- renderer .draw_path (gc , tpath , affine , rgbFace )
287
+ withSimplePatchShadow = _subclass_with_normal (effect_class = SimplePatchShadow )
274
288
275
289
276
290
class SimpleLineShadow (AbstractPathEffect ):
0 commit comments