Guest User

Untitled

a guest
Jan 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. import seaborn as sns
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. import glob
  6.  
  7. # Load data set
  8. dataset = { 1:{"Oxy":[], "De-oxy":[]}, 2:{"Oxy":[], "De-oxy":[]}, 3:{"Oxy":[], "De-oxy":[]}, 4:{"Oxy":[], "De-oxy":[]},
  9. 5:{"Oxy":[], "De-oxy":[]}, 6:{"Oxy":[], "De-oxy":[]}, 7:{"Oxy":[], "De-oxy":[]}, 8:{"Oxy":[], "De-oxy":[]}, 9:{"Oxy":[], "De-oxy":[]}, 10:{"Oxy":[], "De-oxy":[]},
  10. 11:{"Oxy":[], "De-oxy":[]}, 12:{"Oxy":[], "De-oxy":[]}, 13:{"Oxy":[], "De-oxy":[]}, 14:{"Oxy":[], "De-oxy":[]},
  11. 15:{"Oxy":[], "De-oxy":[]}, 16:{"Oxy":[], "De-oxy":[]}, 17:{"Oxy":[], "De-oxy":[]}, 18:{"Oxy":[], "De-oxy":[]}, 19:{"Oxy":[], "De-oxy":[]}, 20:{"Oxy":[], "De-oxy":[]},
  12. 21:{"Oxy":[], "De-oxy":[]}, 22:{"Oxy":[], "De-oxy":[]}, 23:{"Oxy":[], "De-oxy":[]}, 24:{"Oxy":[], "De-oxy":[]}, 25:{"Oxy":[], "De-oxy":[]}, 26:{"Oxy":[], "De-oxy":[]}, 27:{"Oxy":[], "De-oxy":[]}, 28:{"Oxy":[], "De-oxy":[]}, 29:{"Oxy":[], "De-oxy":[]}, 30:{"Oxy":[], "De-oxy":[]}}
  13.  
  14.  
  15. oxy_files = glob.glob("/Users/gdvlr/Documents/MATLAB/Subject-output/Oxy/*.txt")
  16. deoxy_files = glob.glob("/Users/gdvlr/Documents/MATLAB/Subject-output/DeOxy/*.txt")
  17.  
  18. for item in sorted(oxy_files): # Put all oxy readings in dataset_oxy
  19. with open(item) as file:
  20. content = ""
  21. for line in file:
  22. content = content + line.replace("n", ",")
  23. items = content.split(',')
  24.  
  25. count = 1
  26. for i in items:
  27. if (i == "NaN"):
  28. i = "0"
  29. if ( count < 31 ):
  30. dataset[count]['Oxy'].append('%.08f' % float(i))
  31. else:
  32. pass
  33. count = count + 1
  34.  
  35. for item in sorted(deoxy_files): # Put all de-oxy readings in dataset_deoxy
  36. with open(item) as file:
  37. content = ""
  38. for line in file:
  39. content = content + line.replace("n", ",")
  40. items = content.split(',')
  41.  
  42. count = 1
  43. for i in items:
  44. if (i == "NaN"):
  45. i = 0
  46. if ( count < 31 ):
  47. dataset[count]['De-oxy'].append('%.08f' % float(i))
  48. else:
  49. pass
  50. count = count + 1
  51.  
  52. fig = plt.figure(figsize = (15,10))
  53. ax = plt.gca()
  54. j = 1
  55.  
  56. for a in sorted(dataset.keys()):
  57. construct = {}
  58. construct[a] = dict(zip(dataset[a]['Oxy'], dataset[a]['De-oxy']))
  59. val = np.asarray(construct) # This is where the issue lies
  60. subax = plt.subplot(5,6,j)
  61.  
  62. try:
  63. sns.distplot(val, bins=29, hist=True, kde=True, rug=True,
  64. ax = subax, color = 'k', norm_hist = True) # This generates input errors: x must be 1D or 2D
  65.  
  66. except Exception as Ex:
  67. print Ex
  68.  
  69. subax.set_title("Sensor " + str(a))
  70. subax.set_xlim(-5,5)
  71.  
  72. j += 1
  73.  
  74. plt.subplots_adjust(left = 0.06, right = 0.99, bottom = 0.07,
  75. top = 0.92, wspace = 0.14, hspace = 0.6)
  76.  
  77. fig.text(0.5, 0.02, 'De-oxy', ha ='center', fontsize = 15)
  78. fig.text(0.02, 0.5, 'Oxy', ha ='center',
  79. rotation='vertical', fontsize = 15)
  80.  
  81. plt.show()
Add Comment
Please, Sign In to add comment