save
This commit is contained in:
@@ -662,7 +662,7 @@ print("\nFirst few rows:")
|
||||
print(df.head())
|
||||
|
||||
# Hardcode specific patient names
|
||||
patient_names = ['6ccda8c6']
|
||||
patient_names = ['113c1470']
|
||||
|
||||
# Define the functional systems (columns to plot) - adjust based on actual column names
|
||||
functional_systems = ['EDSS', 'Visual', 'Sensory', 'Motor', 'Brainstem', 'Cerebellar', 'Autonomic', 'Bladder', 'Intellectual']
|
||||
@@ -672,7 +672,7 @@ num_plots = len(functional_systems)
|
||||
num_cols = 2
|
||||
num_rows = (num_plots + num_cols - 1) // num_cols # Ceiling division
|
||||
|
||||
fig, axes = plt.subplots(num_rows, num_cols, figsize=(15, 4*num_rows), sharex=True)
|
||||
fig, axes = plt.subplots(num_rows, num_cols, figsize=(15, 4*num_rows), sharex=False) # Changed sharex=False
|
||||
if num_plots == 1:
|
||||
axes = [axes]
|
||||
elif num_rows == 1:
|
||||
@@ -733,6 +733,130 @@ for i in range(len(functional_systems)):
|
||||
if i >= len(axes) - num_cols: # Last row
|
||||
axes[i].set_xlabel('Date')
|
||||
|
||||
# Force date formatting on all axes
|
||||
for ax in axes:
|
||||
ax.tick_params(axis='x', rotation=45)
|
||||
ax.xaxis.set_major_formatter(plt.matplotlib.dates.DateFormatter('%Y-%m-%d'))
|
||||
ax.xaxis.set_major_locator(plt.matplotlib.dates.MonthLocator())
|
||||
|
||||
# Automatically format x-axis dates
|
||||
plt.gcf().autofmt_xdate()
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
##
|
||||
|
||||
|
||||
# %% name
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
from datetime import datetime
|
||||
import numpy as np
|
||||
|
||||
# Load the data
|
||||
file_path = '/home/shahin/Lab/Doktorarbeit/Barcelona/Data/Join_edssandsub.tsv'
|
||||
df = pd.read_csv(file_path, sep='\t')
|
||||
|
||||
# Convert MedDatum to datetime
|
||||
df['MedDatum'] = pd.to_datetime(df['MedDatum'])
|
||||
|
||||
# Check what columns actually exist in the dataset
|
||||
print("Available columns:")
|
||||
print(df.columns.tolist())
|
||||
print("\nFirst few rows:")
|
||||
print(df.head())
|
||||
|
||||
# Check data types
|
||||
print("\nData types:")
|
||||
print(df.dtypes)
|
||||
|
||||
# Hardcode specific patient names
|
||||
patient_names = ['6ccda8c6']
|
||||
|
||||
# Define the functional systems (columns to plot)
|
||||
functional_systems = ['EDSS', 'Visual', 'Sensory', 'Motor', 'Brainstem', 'Cerebellar', 'Autonomic', 'Bladder', 'Intellectual']
|
||||
|
||||
# Create subplots
|
||||
num_plots = len(functional_systems)
|
||||
num_cols = 2
|
||||
num_rows = (num_plots + num_cols - 1) // num_cols
|
||||
|
||||
fig, axes = plt.subplots(num_rows, num_cols, figsize=(15, 4*num_rows), sharex=False)
|
||||
if num_plots == 1:
|
||||
axes = [axes]
|
||||
elif num_rows == 1:
|
||||
axes = axes
|
||||
else:
|
||||
axes = axes.flatten()
|
||||
|
||||
# Plot for the hardcoded patient
|
||||
for i, system in enumerate(functional_systems):
|
||||
# Filter data for this specific patient
|
||||
patient_data = df[df['unique_id'] == patient_names[0]].sort_values('MedDatum')
|
||||
|
||||
# Check if patient data exists
|
||||
if patient_data.empty:
|
||||
print(f"No data found for patient: {patient_names[0]}")
|
||||
axes[i].set_title(f'Functional System: {system} (No data)')
|
||||
axes[i].set_ylabel('Score')
|
||||
continue
|
||||
|
||||
# Check if the system column exists
|
||||
if system in patient_data.columns:
|
||||
# Plot only valid data (non-null values)
|
||||
valid_data = patient_data.dropna(subset=[system])
|
||||
|
||||
if not valid_data.empty:
|
||||
# Ensure MedDatum is properly formatted for plotting
|
||||
axes[i].plot(valid_data['MedDatum'], valid_data[system], marker='o', linewidth=2, label=system)
|
||||
axes[i].set_ylabel('Score')
|
||||
axes[i].set_title(f'Functional System: {system}')
|
||||
axes[i].grid(True, alpha=0.3)
|
||||
axes[i].legend()
|
||||
else:
|
||||
axes[i].set_title(f'Functional System: {system} (No valid data)')
|
||||
axes[i].set_ylabel('Score')
|
||||
else:
|
||||
# Try to find similar column names
|
||||
found_column = None
|
||||
for col in df.columns:
|
||||
if system.lower() in col.lower():
|
||||
found_column = col
|
||||
break
|
||||
|
||||
if found_column:
|
||||
valid_data = patient_data.dropna(subset=[found_column])
|
||||
if not valid_data.empty:
|
||||
axes[i].plot(valid_data['MedDatum'], valid_data[found_column], marker='o', linewidth=2, label=found_column)
|
||||
axes[i].set_ylabel('Score')
|
||||
axes[i].set_title(f'Functional System: {system} (found as: {found_column})')
|
||||
axes[i].grid(True, alpha=0.3)
|
||||
axes[i].legend()
|
||||
else:
|
||||
axes[i].set_title(f'Functional System: {system} (No valid data)')
|
||||
axes[i].set_ylabel('Score')
|
||||
else:
|
||||
axes[i].set_title(f'Functional System: {system} (Column not found)')
|
||||
axes[i].set_ylabel('Score')
|
||||
|
||||
# Hide empty subplots
|
||||
for i in range(len(functional_systems), len(axes)):
|
||||
axes[i].set_visible(False)
|
||||
|
||||
# Set x-axis label for the last row only
|
||||
for i in range(len(functional_systems)):
|
||||
if i >= len(axes) - num_cols: # Last row
|
||||
axes[i].set_xlabel('Date')
|
||||
|
||||
# Format x-axis dates
|
||||
for ax in axes:
|
||||
if ax.get_lines(): # Only format if there are lines to plot
|
||||
ax.tick_params(axis='x', rotation=45)
|
||||
ax.xaxis.set_major_formatter(plt.matplotlib.dates.DateFormatter('%Y-%m-%d'))
|
||||
|
||||
# Automatically adjust layout
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user