Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import seaborn as sns
- import pandas as pd
- import matplotlib.pyplot as plt
- import numpy as np
- import glob
- # Load data set
- dataset = { 1:{"Oxy":[], "De-oxy":[]}, 2:{"Oxy":[], "De-oxy":[]}, 3:{"Oxy":[], "De-oxy":[]}, 4:{"Oxy":[], "De-oxy":[]},
- 5:{"Oxy":[], "De-oxy":[]}, 6:{"Oxy":[], "De-oxy":[]}, 7:{"Oxy":[], "De-oxy":[]}, 8:{"Oxy":[], "De-oxy":[]}, 9:{"Oxy":[], "De-oxy":[]}, 10:{"Oxy":[], "De-oxy":[]},
- 11:{"Oxy":[], "De-oxy":[]}, 12:{"Oxy":[], "De-oxy":[]}, 13:{"Oxy":[], "De-oxy":[]}, 14:{"Oxy":[], "De-oxy":[]},
- 15:{"Oxy":[], "De-oxy":[]}, 16:{"Oxy":[], "De-oxy":[]}, 17:{"Oxy":[], "De-oxy":[]}, 18:{"Oxy":[], "De-oxy":[]}, 19:{"Oxy":[], "De-oxy":[]}, 20:{"Oxy":[], "De-oxy":[]},
- 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":[]}}
- oxy_files = glob.glob("/Users/gdvlr/Documents/MATLAB/Subject-output/Oxy/*.txt")
- deoxy_files = glob.glob("/Users/gdvlr/Documents/MATLAB/Subject-output/DeOxy/*.txt")
- for item in sorted(oxy_files): # Put all oxy readings in dataset_oxy
- with open(item) as file:
- content = ""
- for line in file:
- content = content + line.replace("n", ",")
- items = content.split(',')
- count = 1
- for i in items:
- if (i == "NaN"):
- i = "0"
- if ( count < 31 ):
- dataset[count]['Oxy'].append('%.08f' % float(i))
- else:
- pass
- count = count + 1
- for item in sorted(deoxy_files): # Put all de-oxy readings in dataset_deoxy
- with open(item) as file:
- content = ""
- for line in file:
- content = content + line.replace("n", ",")
- items = content.split(',')
- count = 1
- for i in items:
- if (i == "NaN"):
- i = 0
- if ( count < 31 ):
- dataset[count]['De-oxy'].append('%.08f' % float(i))
- else:
- pass
- count = count + 1
- fig = plt.figure(figsize = (15,10))
- ax = plt.gca()
- j = 1
- for a in sorted(dataset.keys()):
- construct = {}
- construct[a] = dict(zip(dataset[a]['Oxy'], dataset[a]['De-oxy']))
- val = np.asarray(construct) # This is where the issue lies
- subax = plt.subplot(5,6,j)
- try:
- sns.distplot(val, bins=29, hist=True, kde=True, rug=True,
- ax = subax, color = 'k', norm_hist = True) # This generates input errors: x must be 1D or 2D
- except Exception as Ex:
- print Ex
- subax.set_title("Sensor " + str(a))
- subax.set_xlim(-5,5)
- j += 1
- plt.subplots_adjust(left = 0.06, right = 0.99, bottom = 0.07,
- top = 0.92, wspace = 0.14, hspace = 0.6)
- fig.text(0.5, 0.02, 'De-oxy', ha ='center', fontsize = 15)
- fig.text(0.02, 0.5, 'Oxy', ha ='center',
- rotation='vertical', fontsize = 15)
- plt.show()
Add Comment
Please, Sign In to add comment