Skip to content
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

XKCD-style doesn't work with LineCollection #2255

Closed
astrofrog opened this issue Jul 28, 2013 · 7 comments
Closed

XKCD-style doesn't work with LineCollection #2255

astrofrog opened this issue Jul 28, 2013 · 7 comments

Comments

@astrofrog
Copy link
Contributor

The following code:

import numpy as np

from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection

plt.xkcd()

lc = LineCollection([([[0.3,0.3], [0.3, 0.7]])])

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.add_collection(lc)
ax.set_xlim(0., 1.)
ax.set_ylim(0., 1.)
fig.savefig('test.png')

produces the following plot:

test

i.e. the blue line is not xicdified. Is there an easy way to fix this?

cc @jakevdp

@mdboom
Copy link
Member

mdboom commented Jul 28, 2013

Unfortunately not without sacrificing performance of LineCollection.

@astrofrog
Copy link
Contributor Author

@mdboom - I don't mind if this doesn't get fixed in Matplotlib, but would it be possible to provide a workaround for cases where this is wanted?

On the other hand, maybe this could be made an option of plt.xkcd (that is off by default?)

@mdboom
Copy link
Member

mdboom commented Jul 29, 2013

The short answer to doing this outside is to use a list of Lines rather than a LineCollection -- but that's easier said than done if you're using some higher-level plotting function that produces a LineCollection.

Having looked at this again in more detail --- here's the thing that makes it hard. For vector format, Collections are implemented by storing the path only once (as a "stamp") and then referencing it multiple times, usually with some sort of translation or other affine transformation. Since when we create the "stamps" we don't know the resulting scale that the path will ultimately be rendered at, we can't determine how much to subsample the line to add the "wiggles". So getting this to work across all backends would require turning that very important optimization off at least when a wiggly line is requested, and that felt like more hassle than it was worth at the time.

@astrofrog
Copy link
Contributor Author

@mdboom - in my case, I'm producing the LineCollection, so I can just switch to using a list of Lines instead. I agree it's not really worth the time to try and fix this.

@dmcdougall
Copy link
Member

I'm going to close this as a 'wontfix' for the reasons @mdboom has outlined above.

@liangz0707
Copy link

@mdboom I meet this problem when use "PatchCollection". I want to know if it be changed know?

@tacaswell
Copy link
Member

Same idea, create each patch independently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants