peterstangl / svg2data

A Python module for reading data from a plot provided as SVG file.
GNU General Public License v2.0
21 stars 3 forks source link

Ploting fails. get_axes(lines, width, height) produces an error. #3

Open wobbuuu opened 4 years ago

wobbuuu commented 4 years ago

Hi! I found your utility here and feel like it may be very useful for me. I try to use it as manual says but got an error:

from svg2data import svg2data
data = svg2data("/data/test.svg")

Produces:

ValueError                                Traceback (most recent call last)
<ipython-input-2-15f3cf48a742> in <module>
----> 1 data = svg2data("/data/test.svg")
      2 data.writesvg('/data/newfile.svg')

~/Downloads/svg2data-master/svg2data.py in __init__(self, filename, test, debug)
     38             self._tree = ET.parse(filename)
     39             root = self._tree.getroot()
---> 40             width = float(root.attrib['width'])
     41             height = float(root.attrib['height'])
     42 

ValueError: could not convert string to float: '210mm'

when I changed sources to:

width = float(root.attrib['width'][:-2])
height = float(root.attrib['height'][:-2])

I was able to read and write svg file in the debug mode debug='get_axes', but I can't figure out how to fix other parts of the code which are responsible for plotting.

Is it a problem of my sample svg file or not? Could you help me to fix this issue?

Thanks, Anton

peterstangl commented 4 years ago

@wobbuuu I'm sorry, I completely overlooked this issue. The problem is that at the moment the code doesn't deal with units like mm. The code has mostly been used on SVG files generated by inkscape from PDF files and there I have never encountered units in the SVG files. Of course the units are proper SVG, so your SVG file has no problem per se, but at the moment the code cannot handle it.