[newbie] plotting pairs of data

H

hugocoolens

I have a data set for which x and y-values are presented as pairs of
floating point numbers:
e.g. 0.0364771 0.55569 is the first pair
.. 0.132688 0.808496 is the second pair
..
..

The data is available in Python in this format:
['0.0364771 0.55569', '0.132688 0.808496', '0.232877 0.832833',
'0.332702 0.849128', '0.432695 0.862158']

I suppose it is possible to plot x versus y using matplotlib, maybe
separating the data first in two arrays, but I'm not sure whether this
is necessary.
Can anyone here help me further

thanks
hugo
 
T

Thomas Bach

The data is available in Python in this format:
['0.0364771 0.55569', '0.132688 0.808496', '0.232877 0.832833',
'0.332702 0.849128', '0.432695 0.862158']

I suppose it is possible to plot x versus y using matplotlib, maybe
separating the data first in two arrays, but I'm not sure whether this
is necessary.

I think, yes it is necessary to split the data in separate
lists/arrays. Although I find it annoying, too.

In case that not only the if, but also the how is the matter of your
question something like

xs = [ float(x) for x, _ in map(str.split, l) ]
ys = [ float(y) for _, y in map(str.split, l) ]

should do the trick.

Regards,
Thomas Bach.
 
M

Miki Tebeka

['0.0364771 0.55569', '0.132688 0.808496', '0.232877 0.832833',
'0.332702 0.849128', '0.432695 0.862158']
xs = [ float(x) for x, _ in map(str.split, l) ]
ys = [ float(y) for _, y in map(str.split, l) ]
Let's play golf :)
xs, ys = zip(*(map(float, s.split()) for s in l))
 
M

Miki Tebeka

['0.0364771 0.55569', '0.132688 0.808496', '0.232877 0.832833',
'0.332702 0.849128', '0.432695 0.862158']
xs = [ float(x) for x, _ in map(str.split, l) ]
ys = [ float(y) for _, y in map(str.split, l) ]
Let's play golf :)
xs, ys = zip(*(map(float, s.split()) for s in l))
 
H

hugocoolens

The data is available in Python in this format:
['0.0364771 0.55569', '0.132688 0.808496', '0.232877 0.832833',
'0.332702 0.849128', '0.432695 0.862158']
I suppose it is possible to plot x versus y using matplotlib, maybe
separating the data first in two arrays, but I'm not sure whether this
is necessary.

I think, yes it is necessary to split the data in separate
lists/arrays. Although I find it annoying, too.

In case that not only the if, but also the how is the matter of your
question something like

xs = [ float(x) for x, _ in map(str.split, l) ]
ys = [ float(y) for _, y in map(str.split, l) ]

should do the trick.

Regards,
        Thomas Bach.

thanks Thomas this works nicely

hugo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top