Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- LINES_PER_TABLE = 5
- TITLE_LINE=0
- LINE_FOR_X_1 = 1
- LINE_FOR_X_2 = 2
- LINE_FOR_Y = 3
- data=[]
- title=[]
- x=[]
- x1=[]
- x2=[]
- y=[]
- ######################################
- # In this program, data is read from #
- # "data.csv" to be graphed using x1 #
- # and x2 to determine the value for x#
- # according too the below equation #
- ######################################
- #equation here
- def equation(x1,x2):
- return x1 / x2
- with open("data.csv", "r") as f:
- data = list(f)
- for line in data:
- # get line titles
- if data.index(line) % LINES_PER_TABLE == TITLE_LINE:
- title.append(line)
- #get x1
- if data.index(line) % LINES_PER_TABLE == LINE_FOR_X_1:
- temp = []
- for value in line.strip('\n').split(","):
- temp.append(float(value))
- x1.append(temp)
- #get x2
- if data.index(line) % LINES_PER_TABLE == LINE_FOR_X_2:
- temp = []
- for value in line.strip('\n').split(","):
- temp.append(float(value))
- x2.append(temp)
- #get y
- if data.index(line) % LINES_PER_TABLE == LINE_FOR_Y:
- temp = []
- for value in line.strip('\n').split(","):
- temp.append(float(value))
- y.append(temp)
- #calculate x
- for i in range(len(title)):
- x.append([])
- for j in range(len(x1[i])):
- x[i].append(equation(x1[i][j], x2[i][j]))
- #plot x vs y
- for i in range(len(y)):
- plt.plot(x[i], y[i], label=title[i])
- ax = plt.gca()
- ax.set_aspect(1)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement