You are on page 1of 1

"importing numpy to convert list to array"

import numpy as np
"importing pyplot to plot x, y"
import matplotlib.pyplot as plt
"opening file in read mode"
f=open("xy.txt","r");
"reading all lines"
lines=f.readlines();
"creating empty lists for x, y"
x=list();
y=list();
"for each line "
for line in lines:
"split the line into words"
words=line.split(" ");
"word it to float and append to x"
x.append(float(words[0]));
"word it to float and append to y"
y.append(float(words[1]));
"converting list to array"
x=np.array(x);
y=np.array(y);
"closing file"
f.close
"plottting x,y
plt.plot(x,y)

plt.xlabel('x-axis');
plt.ylabel('y-axis');
plt.title('exponential equation')

You might also like