mardi 5 juillet 2016

Plotting graph of text file with strings and integers at the same lines

I am trying to plot a graph using a txt data file of followig arrangement way:

{"alpha": 77.6, "beta": 135, "gamma": 342, "delta": 86.3}

{"alpha": 77.3, "beta": 140, "gamma": 332, "delta": 82.3}

......

(300++ lines below with similar arrangements)

A normal table should work with the following code(and that's what I want) :

def get_points(x,y):
    a = 'xyz/examples.txt'
    data = np.genfromtxt(a,delimiter=',',skip_header=1)
    x_axis = data[:,x]
    y_axis = data[:,y]
    plt.plot(x_axis,y_axis)
    plt.xlabel('x')
    plt.ylabel('y')
    plt.show()

get_points(0,2)

since I am trying to make a code which you can change the x- and y- axis as you like. However, it won't work in this case since the headers and the values are at the same lines for each of them.

May I know if there is any way to remove the headers or extract the integers out of the data etc?Thanks!!!

Aucun commentaire:

Enregistrer un commentaire