From 053968eda8f35d3ee94ae0f1487fb25f24191623 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Tue, 21 May 2013 16:44:58 +0100 Subject: [PATCH] Added parameters to the xkcd function. Fixed deprecation warning on Path. --- doc/users/whats_new.rst | 6 ++++-- lib/matplotlib/path.py | 8 ++++---- lib/matplotlib/pyplot.py | 13 +++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index 381dbd1f1ef6..15fd2465d781 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -36,8 +36,10 @@ and Emf backends. See :ref:`changes_in_1_3` for a complete list. To give your plots a sense of authority that they may be missing, Michael Droettboom (inspired by the work of many others in :ghpull:`1329`) has added an `xkcd-style `_ sketch -plotting mode. To use it, simply call `pyplot.xkcd` before creating -your plot. +plotting mode. To use it, simply call :func:`matplotlib.pyplot.xkcd` +before creating your plot. For really fine control, it is also possible +to modify each artist's sketch parameters individually with +:meth:`matplotlib.artist.Artist.set_sketch_params`. .. plot:: mpl_examples/showcase/xkcd.py diff --git a/lib/matplotlib/path.py b/lib/matplotlib/path.py index 6f45774ead94..1e0d1a43afd7 100644 --- a/lib/matplotlib/path.py +++ b/lib/matplotlib/path.py @@ -433,10 +433,10 @@ def cleaned(self, transform=None, remove_nans=False, clip=None, Path instance with cleaned up vertices and codes. """ - vertices, codes = cleanup_path(self, transform, - remove_nans, clip, - snap, stroke_width, - simplify, curves, sketch) + vertices, codes = _path.cleanup_path(self, transform, + remove_nans, clip, + snap, stroke_width, + simplify, curves, sketch) internals = {'should_simplify': self.should_simplify and not simplify, 'has_nonfinite': self.has_nonfinite and not remove_nans, 'simplify_threshold': self.simplify_threshold, diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index fd9a5c6b0c91..c287bb7100e6 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -250,7 +250,7 @@ def setp(*args, **kwargs): return ret -def xkcd(): +def xkcd(scale=1, length=100, randomness=2): """ Turns on `xkcd `_ sketch-style drawing mode. This will only have effect on things drawn after this function is @@ -259,6 +259,15 @@ def xkcd(): For best results, the "Humor Sans" font should be installed: it is not included with matplotlib. + Parameters + ---------- + scale: float, optional + The amplitude of the wiggle perpendicular to the source line. + length: float, optional + The length of the wiggle along the line. + randomness: float, optional + The scale factor by which the length is shrunken or expanded. + This function works by a number of rcParams, so it will probably override others you have set before. @@ -282,7 +291,7 @@ def xkcd(): try: rcParams['font.family'] = ['Humor Sans', 'Comic Sans MS'] rcParams['font.size'] = 14.0 - rcParams['path.sketch'] = (1, 100, 2) + rcParams['path.sketch'] = (scale, length, randomness) rcParams['path.effects'] = [ patheffects.withStroke(linewidth=4, foreground="w")] rcParams['axes.linewidth'] = 1.5