On Mar 4, 2009, at 7:59 PM, compound eye wrote:

>
> Hello,
>
> I've got lots of data as numbers in xml files, which I would like to
> be able to plot
>
> I've just started using sage today, and was wondering if someone could
> please point me to an example of how to make a list of 2d point and
> how to plot them on a 2d graph.
>
> ultimately I want to import data which I have as xml and visualise it.
>
> any suggestions?

I would google xml parsing in Python--anything that is shipped with  
Python is shipped with Sage (and if it's not, you can easily install  
it). For example

data = """<xml>
        <array>
                <real>-0.47238370776176453</real>
                <real>2616.4930366660001</real>
        </array>
        <array>
                <real>-0.45421510934829712</real>
                <real>2616.502291666</real>
        </array>
        <array>
                <real>-0.43604651093482971</real>
                <real>2616.512025</real>
        </array>
        <array>
                <real>-0.43604651093482971</real>
                <real>2616.5217834999999</real>
        </array>
        <array>
                <real>-0.43604651093482971</real>
                <real>2616.5314666660001</real>
        </array>
        <array>
                <real>-0.43604651093482971</real>
                <real>2616.541297666</real>
        </array>
        <array>
                <real>-0.4178779125213623</real>
                <real>2616.5510479999998</real>
        </array>
</xml>"""

from xml.dom import minidom
doc = minidom.parseString(data)

L = []
for a in doc.firstChild.childNodes:
     if a.nodeName == 'array':
        x = float(a.childNodes[1].firstChild.data)
        y = float(a.childNodes[3].firstChild.data)
        L.append((x,y))
list_plot(L)


You can also just remove all the XML cruft and get the raw list of  
numbers

import re
plain_data = re.sub('<[^>]*?>', '', data).split()
L = [(float(x), float(y)) for x,y in zip(plain_data[0::2], plain_data 
[1::2])]
list_plot(L)

- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to