Skip to content

Instantly share code, notes, and snippets.

Created February 28, 2013 18:54
Show Gist options
  • Save anonymous/5059144 to your computer and use it in GitHub Desktop.
Save anonymous/5059144 to your computer and use it in GitHub Desktop.
remove viewBox attrib and set size(svg_utils issue #1)
import matplotlib as pyplot
from lxml import etree
#do some plotting
plt.savefig(fig_file)
width, height = '3.8in', '2.8in'
with file(fig_file, 'r') as fid:
tree = etree.parse(fid)
root = tree.getroot()
root.attrib.pop('viewBox')
root.attrib['width']=width
root.attrib['height']=height
with file(fig_file, 'w') as fid:
tree.write(fid, pretty_print=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment