beautiful plot

This commit is contained in:
2026-01-19 01:26:14 +01:00
parent 8f34f06578
commit a1a8abfb8e
2 changed files with 199 additions and 20 deletions

View File

@@ -407,7 +407,7 @@ import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import dataframe_image as dfi
# Load data
df = pd.read_csv("/home/shahin/Lab/Doktorarbeit/Barcelona/Data/Join_edssandsub.tsv", sep='\t')
@@ -491,32 +491,76 @@ for gt_col, result_col in column_mapping.items():
'Match %': round(percentage, 1)
})
# 4. Prepare Data for Plotting
# 4. Prepare Data
match_df = pd.DataFrame(data_list)
# Clean up labels: Replace underscores with spaces and capitalize
match_df['GT'] = match_df['GT'].str.replace('_', ' ').str.title()
match_df = match_df.sort_values('Match %', ascending=False)
# Handle case where no matches were found
if len(match_df) == 0:
print("No valid column pairs found for comparison")
exit()
# 5. Create a "Beautiful" Table using Seaborn Heatmap
def create_luxury_table(df, output_file="edss_agreement.png"):
# Set the aesthetic style
sns.set_theme(style="white", font="sans-serif")
# 5. Create the Plot
plt.figure(figsize=(10, 8))
sns.set_theme(style="white")
# Prepare data for heatmap
plot_data = df.set_index('GT')[['Match %']]
# Create heatmap
ax = sns.heatmap(
match_df.set_index('GT')[['Match %']], # Just the percentage column
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
)
# Initialize the figure
# Height is dynamic based on number of rows
fig, ax = plt.subplots(figsize=(8, len(df) * 0.6))
plt.title('Agreement Percentage (Tolerance ±0.5)', pad=20)
plt.tight_layout()
# Create a custom diverging color map (Deep Red -> Mustard -> Emerald)
# This looks more professional than standard 'RdYlGn'
cmap = sns.diverging_palette(15, 135, s=80, l=55, as_cmap=True)
# Draw the heatmap
sns.heatmap(
plot_data,
annot=True,
fmt=".1f",
cmap=cmap,
center=85, # Centers the color transition
vmin=50, vmax=100, # Range of the gradient
linewidths=2,
linecolor='white',
cbar=False, # Remove color bar for a "table" look
annot_kws={"size": 14, "weight": "bold", "family": "sans-serif"}
)
# Styling the Axes (Turning the heatmap into a table)
ax.set_xlabel("")
ax.set_ylabel("")
ax.xaxis.tick_top() # Move "Match %" label to top
ax.set_xticklabels(['Agreement (%)'], fontsize=14, fontweight='bold', color='#2c3e50')
ax.tick_params(axis='y', labelsize=12, labelcolor='#2c3e50', length=0)
# Add a thin border around the plot
for _, spine in ax.spines.items():
spine.set_visible(True)
spine.set_color('#ecf0f1')
plt.title('EDSS Subcategory Consistency Analysis', fontsize=16, pad=40, fontweight='bold', color='#2c3e50')
# Add a subtle footer
plt.figtext(0.5, 0.02, "Tolerance: ±0.5 points | N = [Total Samples]",
wrap=True, horizontalalignment='center', fontsize=10, color='gray', style='italic')
# Save with high resolution
plt.tight_layout()
plt.savefig(output_file, dpi=300, bbox_inches='tight')
print(f"Beautiful table saved as {output_file}")
# Execute
create_luxury_table(match_df)
# Run the function
save_styled_table(match_df)
# 6. Save as SVG
#plt.savefig("agreement_table.svg", format='svg', dpi=300, bbox_inches='tight')
#print("Successfully saved agreement_table.svg")