MGP_Mike_Dijkhof/ScatterBoxplotter.py

73 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
"""
Created on Fri May 14 09:18:32 2021
@author: Dijkhofmf
"""
# Import stuff
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import preprocessing
#%% Import data and path
Path = 'I:\Mike Dijkhof\Connecare MGP\Data\FinalFiles'
# Set path
os.chdir(Path)
#%% Create DF
FinalDF = pd.DataFrame(pd.read_csv('FinalDataset.csv'))
X = pd.DataFrame(FinalDF)
cols = X.drop('Pt Type', axis=1)
ID = X['Study ID']
y = X['Pt Type']
y= y.replace('Healthy', 'No-complication')
X = X.drop(['Pt Type', 'Study ID'], axis=1)
#%%
X1 = pd.DataFrame(preprocessing.scale(X), columns=X.columns)
X1['Pt Type'] = y
X1.set_index(ID)
#%%
X1.columns = ['Age (years)', 'Gender', 'Daily alcohol use', 'Medication',
'ASA-classification', 'Recurrent disease?', 'Comorb',
'Independent, with others', 'Smokes cigarettes/sigar', 'BMI', 'GFI',
'HADS_A', 'HADS Depression', 'ADL', 'iADL', 'TUG', 'Handgrip strength',
'Avg. Steps/day', 'Avg. MVPA/day', 'Pt Type']
plots = X1.columns
#%%
import matplotlib.pylab as pylab
params = {'legend.fontsize': 'x-large',
'axes.labelsize': 'x-large',
'axes.titlesize':'x-large',
'xtick.labelsize':'x-large',
'ytick.labelsize':'x-large'}
pylab.rcParams.update(params)
plots = plots[1:]
namecount=0
for x in plots:
name = str(plots[namecount])
plt.figure(dpi=720)
sns.boxplot(x='Pt Type', y=x, data=X1, boxprops=dict(alpha=0.5))
sns.swarmplot(x='Pt Type', y=x, data=X1)
plt.title('Swarm-boxplot ' + name)
namecount = namecount +1