Question

I need to print data saved in a file in this format:

0.1545,0.68954
0.1548,0.87854
0.2545,0.54854
0.7956,0.41548 

(All values between 0.0 and 1.0) And also the possibility of printing more than one graph in the same figure differentiating them (ie: color, or line style)

I was told to use python to this because of its easiness but all doc I have read and examples like this one are not working for me.

I would really appreciate if somebody could help is for my thesis. I just need python for graph printing, no time to learn in depth.

Was it helpful?

Solution

To load the data:

# open the file so you can read from it
with open("myfile.txt") as inf:
    # for each line in the file,
    # split it on commas (results in a list of strings)
    # then convert each string to a float (results in a list of floats)
    items = (map(float, line.split(",")) for line in inf)
    # transpose (convert columns to rows),
    # then assign each row to a variable)
    xs, ys = zip(*items)

To plot it:

import matplotlib.pyplot as plt

plt.scatter(xs, ys)
plt.show()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top