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.


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!

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 with this one, and it should *probably* work:


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,

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.


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

Any suggestions would be most welcome


Check out the new Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.;164216239;13503038;w?

Matplotlib-users mailing list
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA