Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pandas as pd
- import matplotlib.pyplot as plt
- import seaborn as sns
- from scipy.stats import norm
- import math
- import ptitprince as pt
- # Replace 'B5 segmentSummary (1).csv' with the actual CSV file path
- file_path = 'B5 segmentSummary (1).csv'
- # Read the CSV file into a Pandas DataFrame
- df = pd.read_csv(file_path)
- # Check the available column names
- print(df.columns)
- # Example: Replace 'categorical_column' with the correct column name containing categorical data
- categorical_column = df.columns[0] # Change this to the correct column name
- # Define the range of column positions you want to analyze (columns 6 through 10)
- start_column_position = 6 # Corresponds to column 6
- end_column_position = 9 # Corresponds to column 10
- # Create a list of unique categories in the categorical column
- categories = df[categorical_column].unique()
- # Define a custom color palette for the categories
- colors = sns.color_palette('husl', n_colors=len(categories))
- # Iterate through each category and create separate figures with six Raincloud plots per page
- for idx, category in enumerate(categories):
- category_data = df[df[categorical_column] == category]
- num_plots = end_column_position - start_column_position + 1
- num_pages = math.ceil(num_plots / 6) # Determine the number of pages needed
- for page in range(num_pages):
- plt.figure(figsize=(18, 12))
- for i in range(6):
- plot_num = page * 6 + i
- if plot_num >= num_plots:
- break
- col = df.columns[start_column_position + plot_num]
- # Raincloud plot with different colors for each category
- plt.subplot(2, 6, i + 1)
- pt.RainCloud(data=category_data, x=col, orient='h', width_viol=0.6, width_box=0.4, palette=[colors[idx]])
- plt.title(f'Raincloud Plot\n{category} - {col}')
- plt.tight_layout(rect=[0, 0.03, 1, 0.95]) # Adjust the layout to avoid title overlap
- plt.suptitle(f'{category} Raincloud Plots - Page {page + 1}', fontsize=16)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement