seaborn styled table
This commit is contained in:
@@ -592,3 +592,65 @@ print("\nraw comparison data:")
|
||||
print(comprehensive_matrix.head())
|
||||
|
||||
##
|
||||
|
||||
# %% name
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import seaborn as sns
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Load data
|
||||
df = pd.read_csv("/home/shahin/Lab/Doktorarbeit/Barcelona/Data/Join_edssandsub.tsv", sep='\t')
|
||||
|
||||
# 1. Faster, vectorized computation
|
||||
gt_columns = [col for col in df.columns if col.startswith('GT.')]
|
||||
data_list = []
|
||||
|
||||
for gt_col in gt_columns:
|
||||
base_name = gt_col.replace('GT.', '')
|
||||
result_col = f'result.{base_name}'
|
||||
|
||||
if result_col in df.columns:
|
||||
# Convert to numeric, force invalid to NaN
|
||||
s1 = pd.to_numeric(df[gt_col], errors='coerce')
|
||||
s2 = pd.to_numeric(df[result_col], errors='coerce')
|
||||
|
||||
# Calculate matches (abs difference <= 0.5)
|
||||
# Note: .sum() treats True as 1
|
||||
matches = (np.abs(s1 - s2) <= 0.5).sum()
|
||||
percentage = (matches / len(df)) * 100
|
||||
|
||||
data_list.append({
|
||||
'GT': gt_col.replace('GT.', ''),
|
||||
'Match %': round(percentage, 1)
|
||||
})
|
||||
|
||||
# 2. Prepare Data for Plotting
|
||||
match_df = pd.DataFrame(data_list)
|
||||
# We pivot to get a format suitable for a heatmap
|
||||
plot_data = match_df.set_index('GT')
|
||||
|
||||
# 3. Create the Plot
|
||||
plt.figure(figsize=(10, 8))
|
||||
sns.set_theme(style="white")
|
||||
|
||||
# Create heatmap
|
||||
ax = sns.heatmap(
|
||||
plot_data,
|
||||
annot=True, # Show the numbers in the boxes
|
||||
fmt=".1f", # Format to 1 decimal place
|
||||
cmap="YlGnBu", # Yellow-Green-Blue color palette
|
||||
cbar_kws={'label': 'Agreement (%)'},
|
||||
linewidths=.5
|
||||
)
|
||||
|
||||
plt.title('Agreement Percentage (Tolerance ±0.5)', pad=20)
|
||||
plt.tight_layout()
|
||||
|
||||
# 4. Save as SVG
|
||||
plt.savefig("agreement_table.svg", format='svg')
|
||||
print("Successfully saved agreement_table.svg")
|
||||
|
||||
# Show plot if running in a GUI environment
|
||||
plt.show()
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user