-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Add a "sketch" path filter #1329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5c26a7e
99e2b5e
05bec2c
b7b3272
f157c97
e1e0848
65544a1
c288df2
edb1526
cc61700
9652004
a274a41
4a61f50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,5 +30,7 @@ | |
| X.shape = h, w, 3 | ||
|
|
||
| im = Image.fromstring( "RGB", (w,h), s) | ||
| im.show() | ||
|
|
||
| # Uncomment this line to display the image using ImageMagick's | ||
| # `display` tool. | ||
| # im.show() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentional?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes -- though I should probably remove the line altogether -- this causes ImageMagick's "display" utility to be called during the documentation build.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! That annoys me everytime and I've never got to the bottom of it! 😄 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
|
|
||
| with plt.xkcd(): | ||
| # Based on "Stove Ownership" from XKCD by Randall Monroe | ||
| # http://xkcd.com/418/ | ||
|
|
||
| fig = plt.figure() | ||
| ax = fig.add_axes((0.1, 0.2, 0.8, 0.7)) | ||
| ax.spines['right'].set_color('none') | ||
| ax.spines['top'].set_color('none') | ||
| plt.xticks([]) | ||
| plt.yticks([]) | ||
| ax.set_ylim([-30, 10]) | ||
|
|
||
| data = np.ones(100) | ||
| data[70:] -= np.arange(30) | ||
|
|
||
| plt.annotate( | ||
| 'THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED', | ||
| xy=(70, 1), arrowprops=dict(arrowstyle='->'), xytext=(15, -10)) | ||
|
|
||
| plt.plot(data) | ||
|
|
||
| plt.xlabel('time') | ||
| plt.ylabel('my overall health') | ||
| fig.text( | ||
| 0.5, 0.05, | ||
| '"Stove Ownership" from xkcd by Randall Monroe', | ||
| ha='center') | ||
|
|
||
| # Based on "The Data So Far" from XKCD by Randall Monroe | ||
| # http://xkcd.com/373/ | ||
|
|
||
| fig = plt.figure() | ||
| ax = fig.add_axes((0.1, 0.2, 0.8, 0.7)) | ||
| ax.bar([-0.125, 1.0-0.125], [0, 100], 0.25) | ||
| ax.spines['right'].set_color('none') | ||
| ax.spines['top'].set_color('none') | ||
| ax.xaxis.set_ticks_position('bottom') | ||
| ax.set_xticks([0, 1]) | ||
| ax.set_xlim([-0.5, 1.5]) | ||
| ax.set_ylim([0, 110]) | ||
| ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT']) | ||
| plt.yticks([]) | ||
|
|
||
| plt.title("CLAIMS OF SUPERNATURAL POWERS") | ||
|
|
||
| fig.text( | ||
| 0.5, 0.05, | ||
| '"The Data So Far" from xkcd by Randall Monroe', | ||
| ha='center') | ||
|
|
||
| plt.show() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,8 @@ def __init__(self): | |
| self._url = None | ||
| self._gid = None | ||
| self._snap = None | ||
| self._sketch = rcParams['path.sketch'] | ||
| self._path_effects = rcParams['path.effects'] | ||
|
|
||
| def __getstate__(self): | ||
| d = self.__dict__.copy() | ||
|
|
@@ -456,6 +458,63 @@ def set_snap(self, snap): | |
| """ | ||
| self._snap = snap | ||
|
|
||
| def get_sketch_params(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be keen to use numpydoc form here (https://github.com/matplotlib/matplotlib/wiki/Mep10)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sure -- I didn't notice that. This PR predates MEP10, so I forgot to update it. |
||
| """ | ||
| Returns the sketch parameters for the artist. | ||
|
|
||
| Returns | ||
| ------- | ||
| sketch_params : tuple or `None` | ||
|
|
||
| A 3-tuple with the following elements: | ||
|
|
||
| * `scale`: The amplitude of the wiggle perpendicular to the | ||
| source line. | ||
|
|
||
| * `length`: The length of the wiggle along the line. | ||
|
|
||
| * `randomness`: The scale factor by which the length is | ||
| shrunken or expanded. | ||
|
|
||
| May return `None` if no sketch parameters were set. | ||
| """ | ||
| return self._sketch | ||
|
|
||
| def set_sketch_params(self, scale=None, length=None, randomness=None): | ||
| """ | ||
| Sets the the sketch parameters. | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
||
| scale : float, optional | ||
| The amplitude of the wiggle perpendicular to the source | ||
| line, in pixels. If scale is `None`, or not provided, no | ||
| sketch filter will be provided. | ||
|
|
||
| length : float, optional | ||
| The length of the wiggle along the line, in pixels | ||
| (default 128.0) | ||
|
|
||
| randomness : float, optional | ||
| The scale factor by which the length is shrunken or | ||
| expanded (default 16.0) | ||
| """ | ||
| if scale is None: | ||
| self._sketch = None | ||
| else: | ||
| self._sketch = (scale, length or 128.0, randomness or 16.0) | ||
|
|
||
| def set_path_effects(self, path_effects): | ||
| """ | ||
| set path_effects, which should be a list of instances of | ||
| matplotlib.patheffect._Base class or its derivatives. | ||
| """ | ||
| self._path_effects = path_effects | ||
|
|
||
| def get_path_effects(self): | ||
| return self._path_effects | ||
|
|
||
| def get_figure(self): | ||
| """ | ||
| Return the :class:`~matplotlib.figure.Figure` instance the | ||
|
|
@@ -672,7 +731,7 @@ def update(self, props): | |
| store = self.eventson | ||
| self.eventson = False | ||
| changed = False | ||
|
|
||
| for k, v in props.iteritems(): | ||
| func = getattr(self, 'set_' + k, None) | ||
| if func is None or not callable(func): | ||
|
|
@@ -728,6 +787,8 @@ def update_from(self, other): | |
| self._clippath = other._clippath | ||
| self._lod = other._lod | ||
| self._label = other._label | ||
| self._sketch = other._sketch | ||
| self._path_effects = other._path_effects | ||
| self.pchanged() | ||
|
|
||
| def properties(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -701,6 +701,7 @@ def __init__(self): | |
| self._url = None | ||
| self._gid = None | ||
| self._snap = None | ||
| self._sketch = None | ||
|
|
||
| def copy_properties(self, gc): | ||
| 'Copy properties from gc to self' | ||
|
|
@@ -720,6 +721,7 @@ def copy_properties(self, gc): | |
| self._url = gc._url | ||
| self._gid = gc._gid | ||
| self._snap = gc._snap | ||
| self._sketch = gc._sketch | ||
|
|
||
| def restore(self): | ||
| """ | ||
|
|
@@ -1003,6 +1005,53 @@ def get_hatch_path(self, density=6.0): | |
| return None | ||
| return Path.hatch(self._hatch, density) | ||
|
|
||
| def get_sketch_params(self): | ||
| """ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not an action: We should think about removing the duplicated docstings (duplicated in Artist) from here. |
||
| Returns the sketch parameters for the artist. | ||
|
|
||
| Returns | ||
| ------- | ||
| sketch_params : tuple or `None` | ||
|
|
||
| A 3-tuple with the following elements: | ||
|
|
||
| * `scale`: The amplitude of the wiggle perpendicular to the | ||
| source line. | ||
|
|
||
| * `length`: The length of the wiggle along the line. | ||
|
|
||
| * `randomness`: The scale factor by which the length is | ||
| shrunken or expanded. | ||
|
|
||
| May return `None` if no sketch parameters were set. | ||
| """ | ||
| return self._sketch | ||
|
|
||
| def set_sketch_params(self, scale=None, length=None, randomness=None): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically I don't think these need to be keywords as they are always given (in the draw method). But I agree that keeping the signature consistent is useful. |
||
| """ | ||
| Sets the the sketch parameters. | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
||
| scale : float, optional | ||
| The amplitude of the wiggle perpendicular to the source | ||
| line, in pixels. If scale is `None`, or not provided, no | ||
| sketch filter will be provided. | ||
|
|
||
| length : float, optional | ||
| The length of the wiggle along the line, in pixels | ||
| (default 128.0) | ||
|
|
||
| randomness : float, optional | ||
| The scale factor by which the length is shrunken or | ||
| expanded (default 16.0) | ||
| """ | ||
| if scale is None: | ||
| self._sketch = None | ||
| else: | ||
| self._sketch = (scale, length or 128.0, randomness or 16.0) | ||
|
|
||
|
|
||
| class TimerBase(object): | ||
| ''' | ||
|
|
@@ -1937,7 +1986,7 @@ def print_jpg(self, filename_or_obj, *args, **kwargs): | |
|
|
||
| *quality*: The image quality, on a scale from 1 (worst) to | ||
| 95 (best). The default is 95, if not given in the | ||
| matplotlibrc file in the savefig.jpeg_quality parameter. | ||
| matplotlibrc file in the savefig.jpeg_quality parameter. | ||
| Values above 95 should be avoided; 100 completely | ||
| disables the JPEG quantization stage. | ||
|
|
||
|
|
@@ -1957,7 +2006,7 @@ def print_jpg(self, filename_or_obj, *args, **kwargs): | |
| options = cbook.restrict_dict(kwargs, ['quality', 'optimize', | ||
| 'progressive']) | ||
|
|
||
| if 'quality' not in options: | ||
| if 'quality' not in options: | ||
| options['quality'] = rcParams['savefig.jpeg_quality'] | ||
|
|
||
| return image.save(filename_or_obj, format='jpeg', **options) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path effects on lines deserves to go in here too.