Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Suggestion: Add a filter function for artists #173

Open
haji-ali opened this issue Jun 9, 2017 · 4 comments
Open

Suggestion: Add a filter function for artists #173

haji-ali opened this issue Jun 9, 2017 · 4 comments

Comments

@haji-ali
Copy link

haji-ali commented Jun 9, 2017

When using matplotlib2tikz, sometimes some objects are produced which are invisible in a plot but somehow visible in the pgfplot (usually paths with 'fill opacity=0'). I understand that it is difficult to account for all cases, but I think a nice and easy feature would be for matplotlib2tikz to call a user supplied function that filters unwanted objects.

@nschloe
Copy link
Owner

nschloe commented Jun 9, 2017

An interesting idea! Is there a simple filter you have in mind?

@haji-ali
Copy link
Author

haji-ali commented Jun 9, 2017

I was thinking of providing a function that accepts an object as an argument and returns True when the object should be added to the output, and False otherwise.
If provided, matplotlib2tikz would then call the function when iterating over the children in _recurse in save.py and only add the object if True is returned.

Then, as the user, I would return False if the fillstyle of a line is None or when the object is a PathCollection (since I know I didn't create these objects).

@nschloe
Copy link
Owner

nschloe commented Jun 12, 2017

I guess that's possible. Do you have a good idea for a small test for this?

@haji-ali
Copy link
Author

haji-ali commented Jun 14, 2017

Sure. This code produces a few unnecessary paths

 plt.clf()
 l1, = plt.plot(1, 1, '-k')
 plt.savefig('/tmp/tmp.pdf', bbox_inches='tight')

 from matplotlib2tikz import save as tikz_save
 tikz_save("/tmp/tmp.tex", plt.gcf())

These paths are created by savefig but they are visible when saved in tikz.
So I was thinking of something along the lines of

 tikz_save("/tmp/tmp.tex", plt.gcf(), 
            filter=lambda obj: not isinstance(obj, mpl.collections.PathCollection))

to filter these paths out.

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

No branches or pull requests

2 participants