-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
Also, I invented my own wiggliness algorithm here based on a randomly progressing sine wave. I think Juergen Hasch's filtered noise approach looks better -- we should probably change this to do that. |
That image seems to be a broken link, maybe? No worries -- just curious what you've decided to do with it. |
Oops, my bad. I better put it on github... |
Let's see Matlab match this! :-P |
Very cool. |
Amazing. Unfortunately, this won't make it in 1.2; it's not a bug fix. :) |
This is actually great for doing schematic 'big-picture' plots in a talk where a clean looking plot looks 'too scientific'. |
@@ -337,7 +337,16 @@ def validate_bbox(s): | |||
return None | |||
raise ValueError("bbox should be 'tight' or 'standard'") | |||
|
|||
|
|||
def validate_sketch(s): | |||
if s == 'None' or s is None: |
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.
s
isn't a very explicit variable name. I'm not sure what the matplotlib's coding convention are regarding to this, but I think the code would gain in readibility with a longer variable name such as sketch
.
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.
In cases like this, however, I think using a short variable name is fine. "def validate_sketch(sketch)" looks worse to my eye.
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.
Dunno... Reading the code as a "not matplotlib expert", it didn't seem obvious what s
was. I have for rule not to use one letter variables as they are often confusing for beginners, and I want my code to be easily read and modified by anyone. Explicit is better than implicit.
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.
Your suggestion for a name, "sketch" would not help--it is no more descriptive of what "s" is than "s". "s" is not a sketch, it is an argument of unknown type being checked to see if it takes one of several valid forms.
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.
Probably should make it clear in any documentation that this parameter has to be set prior to any plotting calls, much like with setting font sizes and such. |
sweet! add the |
And doing it to the subplots.py example is really neat! |
I don't have time to test this now, but I just want to say that I like this a lot! |
That's really nice! Now fetch the Ipython crew so we have a whole xkcd python notebook |
Ok, some bugs:
|
Another notebook with some stabs in this direction (though done at the patch level in matplotlib): |
On Saturday, October 6, 2012, Jacob Vanderplas wrote:
|
@WeatherGod: In your animation examples, even lines that are not being changed (e.g. x and y axis) are constantly wobbling around. Did you do that deliberately, or is that an unintended side effect? To me it looks very irritating. |
On Saturday, November 17, 2012, Nikolaus Rath wrote:
The filter is applied whenever the coordinates of the path is accessed. It |
Any reason not to merge this? |
The api for using this is horrible. It needs to have proper kwarg or rcparam access before its mergeable. I've sort of dropped the ball on this one. |
Also note the bugs that I have pointed out earlier. I think this was a great and innovative proof-of-concept, but it is probably best to re-work this. A thought I did have about a possible way to address @Nikratio 's concerns (and would enable proper unit-testing) is an ability to cache a seed number for a path. That way, the random seed would be re-used at each re-draw, resulting in the same sketch every time. This seed could be automatically determined and/or explicitly set. |
FWIW, if my memory serves me, I have a pretty good implementation of this which uses transforms only (with just a couple of bug fixes and if I remember correctly, a single monkey patch). The path filter stuff sounds very useful in this case, but it also sounds like a lot of work and I wonder how widely used it would really be? |
I just wanted to say that it would be very nice to have this in matplotlib, Ondrej On Wed, Mar 6, 2013 at 12:34 PM, Phil Elson notifications@github.comwrote:
|
Thanks for the info Ondrej.
Is it purely for XKCD style plots which show data in a less clinical, semantic form, or are there other usecases which make use of the path filter functionality? |
@@ -1003,6 +1005,42 @@ def get_hatch_path(self, density=6.0): | |||
return None | |||
return Path.hatch(self._hatch, density) | |||
|
|||
def get_sketch_params(self): | |||
""" |
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.
Not an action: We should think about removing the duplicated docstings (duplicated in Artist) from here.
Mike: This is looking good. Please only add commits on top of c288df2 (rather than rebasing / modifying any history) and I would be happy to merge after some of the actions have been addressed/discussed. I love the xkcd rendered version of the docs - very nicely done 😄 |
@pelson: Thanks for the feedback. I believe I have addressed all of your comments. The context manager took some work because the Out of curiosity, why the rebase warning? |
I didn't want to re-read the whole lot again 😄. This all looks good to me. Very nice work 😄 |
Add a "sketch" path filter for XKCD style graphics.
@@ -58,7 +58,7 @@ class _path_module : public Py::ExtensionModule<_path_module> | |||
add_varargs_method("convert_path_to_polygons", &_path_module::convert_path_to_polygons, | |||
"convert_path_to_polygons(path, trans, width, height)"); | |||
add_varargs_method("cleanup_path", &_path_module::cleanup_path, | |||
"cleanup_path(path, trans, remove_nans, clip, snap, simplify, curves)"); | |||
"cleanup_path(path, trans, remove_nans, clip, snap, simplify, curves, sketch_params)"); |
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.
@mdboom - I don't this this string is correct.
Based on the mailing list thread "XKCD style graphs", this adds a sketchy line path filter to matplotlib.
This PR is not complete, but I thought I'd get something up early so we can hack on it together.
To play with this, set the rcParam['path.sketch'] to a tuple (scale, length, randomness), for example (1.0, 128., 16.).
This currently only works with the Agg and PDF backends, though it should be easy enough to add to other vector backends by following the same procedure as the PDF backend. The Mac OS-X backend will require more care, but should be possible as it's been added to
path_cleanup.cpp
.Beyond this, it would be nice to add a convenience function
xkcd_style
, or some such, that thickens the lines, removes the north and east spines, possibly changes the font, etc.