Skip to content

Instantly share code, notes, and snippets.

@btel
Forked from anonymous/gist:5059144
Created July 22, 2013 12:58
Show Gist options
  • Save btel/6053648 to your computer and use it in GitHub Desktop.
Save btel/6053648 to your computer and use it in GitHub Desktop.
edit viewBox in svg_utils
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