Advertisement
UF6

Protein Case 1-9 Gaussian Distribution

UF6
Nov 14th, 2023
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | Source Code | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. import seaborn as sns
  5. from scipy.stats import norm
  6. import math
  7. import ptitprince as pt
  8.  
  9. # Replace 'B5 segmentSummary (1).csv' with the actual CSV file path
  10. file_path = 'B5 segmentSummary (1).csv'
  11.  
  12. # Read the CSV file into a Pandas DataFrame
  13. df = pd.read_csv(file_path)
  14.  
  15. # Check the available column names
  16. print(df.columns)
  17.  
  18. # Example: Replace 'categorical_column' with the correct column name containing categorical data
  19. categorical_column = df.columns[0]  # Change this to the correct column name
  20.  
  21. # Define the range of column positions you want to analyze (columns 6 through 10)
  22. start_column_position = 6  # Corresponds to column 6
  23. end_column_position = 9  # Corresponds to column 10
  24.  
  25. # Create a list of unique categories in the categorical column
  26. categories = df[categorical_column].unique()
  27.  
  28. # Define a custom color palette for the categories
  29. colors = sns.color_palette('husl', n_colors=len(categories))
  30.  
  31. # Iterate through each category and create separate figures with six Raincloud plots per page
  32. for idx, category in enumerate(categories):
  33.     category_data = df[df[categorical_column] == category]
  34.     num_plots = end_column_position - start_column_position + 1
  35.     num_pages = math.ceil(num_plots / 6)  # Determine the number of pages needed
  36.    
  37.     for page in range(num_pages):
  38.         plt.figure(figsize=(18, 12))
  39.        
  40.         for i in range(6):
  41.             plot_num = page * 6 + i
  42.             if plot_num >= num_plots:
  43.                 break
  44.            
  45.             col = df.columns[start_column_position + plot_num]
  46.            
  47.             # Raincloud plot with different colors for each category
  48.             plt.subplot(2, 6, i + 1)
  49.             pt.RainCloud(data=category_data, x=col, orient='h', width_viol=0.6, width_box=0.4, palette=[colors[idx]])
  50.             plt.title(f'Raincloud Plot\n{category} - {col}')
  51.        
  52.         plt.tight_layout(rect=[0, 0.03, 1, 0.95])  # Adjust the layout to avoid title overlap
  53.         plt.suptitle(f'{category} Raincloud Plots - Page {page + 1}', fontsize=16)
  54.         plt.show()
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement