Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. LINES_PER_TABLE = 5
  3. TITLE_LINE=0
  4. LINE_FOR_X_1 = 1
  5. LINE_FOR_X_2 = 2
  6. LINE_FOR_Y = 3
  7.  
  8. data=[]
  9. title=[]
  10. x=[]
  11. x1=[]
  12. x2=[]
  13. y=[]
  14.  
  15.  
  16. f = open("data.csv", "r")
  17.  
  18. # turn file lines into list so you can use .index
  19. for line in f:
  20. data.append(line)
  21.  
  22. with open("data.csv", "r") as f:
  23. date = list(f)
  24. for line in data:
  25. # get line titles
  26. if data.index(line) % LINES_PER_TABLE == TITLE_LINE:
  27. title.append(line)
  28.  
  29. #get x1
  30. if data.index(line) % LINES_PER_TABLE == LINE_FOR_X_1:
  31. temp = []
  32. for value in line.strip('\n').split(","):
  33. temp.append(float(value))
  34. x1.append(temp)
  35.  
  36. #get x2
  37. if data.index(line) % LINES_PER_TABLE == LINE_FOR_X_2:
  38. temp = []
  39. for value in line.strip('\n').split(","):
  40. temp.append(float(value))
  41. x2.append(temp)
  42.  
  43.  
  44.  
  45. #get y
  46. if data.index(line) % LINES_PER_TABLE == LINE_FOR_Y:
  47. temp = []
  48. for value in line.strip('\n').split(","):
  49. temp.append(float(value))
  50. y.append(temp)
  51.  
  52. #calculate x
  53. for i in range(len(title)):
  54. x.append([])
  55. for j in range(len(x1[i])):
  56. ##equation here##
  57. x[i].append(x1[i][j]/x2[i][j])
  58.  
  59. #plot x vs y
  60. for i in range(len(y)):
  61. plt.plot(x[i], y[i], label=title[i])
  62.  
  63. ax = plt.gca()
  64. ax.set_aspect(1)
  65. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement