problems in Inkscape with SVG exported from matplotlib

For the sake of the list, I'm linking the response to my question on the Inkscape mailing list -- this is certainly an Inkscape bug, that their copy-and-paste functionality does not handle use/defs correctly.

However, as the workaround in mpl was easy enough, we don't have to wait for Inkscape to fix what sounds like a difficult problem.

http://sourceforge.net/mailarchive/forum.php?thread_name=3c78ff030803260851l36e71d12n173fb77d4ddc4579%40mail.gmail.com&forum_name=inkscape-devel

Cheers,
Mike

Kaushik Ghose wrote:

···

Hi Mike,

I replaced the current file with your modified one, and it works fine - I pasted three figures together and had not problems. (I am on Windows XP, Python 2.5)

Thanks again for maintaining and enhancing matplotlib!
-Kaushik

Michael Droettboom wrote:

I didn't write the first pass of SVG support, that was done before I got involved -- I'm not sure who to credit, but he or she deserves most of it.

I did add the feature that's causing grief here -- the embedding of character outlines directly in the SVG file.

I've committed a change in SVN (both the trunk and the branch) that should resolve your problem. I've written the inkscape mailing list about the "correct" solution, but I figure we need a workaround in mpl regardless.

If you're not tracking SVN, you can replace your copy of backend_svg.py with this one, and it should *probably* work:

http://matplotlib.svn.sourceforge.net/viewvc/checkout/matplotlib/branches/v0_91_maint/lib/matplotlib/backends/backend_svg.py?revision=5023&pathrev=5023

Cheers,
Mike

Kaushik Ghose wrote:

Hi Mike,

Ah, such prompt, friendly and knowledgeable help!

You're the guy implementing svg support in matplotlib, right? Thanks so much for implementing this!!!
If I can do anything to assist please tell me.

Thanks again,
-Kaushik

Michael Droettboom wrote:

When matplotlib outputs an SVG, each unique character is assigned a numeric id (these are just assigned in order), and inserted as a "def", and then "use"d (referenced) wherever they are used.

When you paste on SVG into another, those names clash, and Inkscape is pulling in the wrong characters when it goes to draw.

Now, my gut feels that this is actually a bug in Inkscape -- pasting of referenced objects from one file into another should reassign new ids. However, I'm not an SVG expert, so I could be wrong, but I think I will take this question over to the Inkscape mailing list anyway.

That said, there are probably some workarounds that matplotlib could make (using a hash of the character's content as the id, for instance). I'll look into that and reply when progress has been made.

Mike

Kaushik Ghose wrote:

Hi Everyone,

I have a peculiar problem, and I wonder if anyone can assist me.

I have two figures generated from matplotlib and saved as svgs. They both print fine, and they load in Inkscape just fine.

However, when I copy one figure and paste it into the other, the pasted figure's labels and text become garbled.

Screenshots on this page
http://assorted-experience.blogspot.com/2008/03/inkscape-matplotlibs-svg-one-strange.html

Any suggestions would be most welcome
Thanks
-Kaushik

-------------------------------------------------------------------------

Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA