Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/FlyRanch/figurefirst
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvb committed Apr 11, 2018
2 parents 6652519 + e2fd543 commit 73ce187
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FigureFirst is a python library to decorate and parse SVG files so they can serve as layout documents for matplotlib figures.

See our github page for readme and examples: http://flyranch.github.io/figurefirst/

Read the docs: http://figurefirst.readthedocs.io/en/latest/source/figurefirst.html#module-figurefirst

Read our Scipy 2017 proceedings: http://conference.scipy.org/proceedings/scipy2017/lindsay.html

If you use FigureFirst, please cite the above paper to help others find FigureFirst.
If you use FigureFirst, please cite the above paper to help others find FigureFirst.
3 changes: 2 additions & 1 deletion figurefirst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
#reload(svg_to_axes)
from . import mpl_functions
from .svg_to_axes import FigureLayout
from . import mpl_fig_to_figurefirst_svg
from . import mpl_fig_to_figurefirst_svg
from . import svg_util
7 changes: 6 additions & 1 deletion figurefirst/svg_to_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class FFSVGText(FFSVGItem,object):

def __init__(self,tagnode):
super(FFSVGItem,self).__init__(tagnode)
#print 'here'
x = float(self.node.getAttribute('x'))
y = float(self.node.getAttribute('y'))
self.p1 = np.array([x,y,1])
Expand All @@ -317,6 +318,7 @@ def __init__(self,tagnode):
#self.p1 = np.array([x,y,1])
#self.p2 = np.array([x+w,h+y,1])
self.load_style()
self.load_text()
self.node.getElementsByTagName('tspan')[0].childNodes[0]

def load_style(self):
Expand Down Expand Up @@ -627,7 +629,10 @@ def __init__(self, layout_filename, autogenlayers=True,make_mplfigures = False,
# it is probably best to assert that the a.r's are the same
# for now
#assert self.layout_user_sx == self.layout_user_sy
assert (np.abs(self.layout_user_sx[0] - self.layout_user_sy[0]) < figurefirst_user_parameters.rounding_tolerance) # rounding errors are a bitch
if np.abs(self.layout_user_sx[0] - self.layout_user_sy[0]) > figurefirst_user_parameters.rounding_tolerance:
warnings.warn("""The the scaling of the user units in x and y are different and may result in unexpected
behavior. Make sure that the aspect ratio defined by the viewbox attribute of the root
SVG node is the same as that given by the document hight and width.""")
if make_mplfigures:
self.make_mplfigures()

Expand Down
33 changes: 33 additions & 0 deletions figurefirst/svg_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#utility functions for dealing with svg files.

def replace_non_unique(in_filename,out_filename,
search_string = 'text_to_replace',
prefix = ''):
"""parse the document 'in_filename' and replace all
instances of the string 'search_string' with the
unique string 'prefix_x'.
Parameters
----------
in_filename : name of the file to parse
out_filename : name of the file to write. If
out_filename is the same as in_filename
then the old document will be overwritten.
search_string : target string to search and replace. Note:
when applying this function to svg layout documents
take care that you don't target strings that are
common strings in the SVG language. e.g. 'label'
prefix : the prefix will be appended with a number and used
to replace each occurance of the search string.
"""

with open(in_filename,'rt') as inf:
strdta = inf.read()
slist = strdta.split(search_string)
outstr = ''.join([s + prefix + '_%s'%(i) for i,s in enumerate(slist[:-1])])
outstr += slist[-1]
with open(out_filename,'wt') as outf:
outf.write(outstr)

0 comments on commit 73ce187

Please sign in to comment.