Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 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. # In this program, data is read from #
  17. # "data.csv" to be graphed using x1 #
  18. # and x2 to determine the value for x#
  19. # according too the below equation #
  20. ######################################
  21.  
  22. #equation here
  23. def equation(x1,x2):
  24. return x1 / x2
  25.  
  26.  
  27.  
  28. with open("data.csv", "r") as f:
  29. data = list(f)
  30. for line in data:
  31. # get line titles
  32. if data.index(line) % LINES_PER_TABLE == TITLE_LINE:
  33. title.append(line)
  34.  
  35. #get x1
  36. if data.index(line) % LINES_PER_TABLE == LINE_FOR_X_1:
  37. temp = []
  38. for value in line.strip('\n').split(","):
  39. temp.append(float(value))
  40. x1.append(temp)
  41.  
  42. #get x2
  43. if data.index(line) % LINES_PER_TABLE == LINE_FOR_X_2:
  44. temp = []
  45. for value in line.strip('\n').split(","):
  46. temp.append(float(value))
  47. x2.append(temp)
  48.  
  49.  
  50.  
  51. #get y
  52. if data.index(line) % LINES_PER_TABLE == LINE_FOR_Y:
  53. temp = []
  54. for value in line.strip('\n').split(","):
  55. temp.append(float(value))
  56. y.append(temp)
  57.  
  58. #calculate x
  59. for i in range(len(title)):
  60. x.append([])
  61. for j in range(len(x1[i])):
  62. x[i].append(equation(x1[i][j], x2[i][j]))
  63.  
  64. #plot x vs y
  65. for i in range(len(y)):
  66. plt.plot(x[i], y[i], label=title[i])
  67.  
  68. ax = plt.gca()
  69. ax.set_aspect(1)
  70. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement