behavior_time_plots.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Mar 13 13:53:26 2024
  4. @author: arefks
  5. """
  6. import os
  7. import pandas as pd
  8. import seaborn as sns
  9. import matplotlib.pyplot as plt
  10. # Get the directory where the code file is located
  11. code_dir = os.path.dirname(os.path.abspath(__file__))
  12. # Get the parent directory of the code directory
  13. parent_dir = os.path.dirname(code_dir)
  14. # Specify the input file path relative to the code file
  15. input_file_path = os.path.join(parent_dir, 'output', 'Normalized_behaviour_data.csv')
  16. # Read the CSV file into a Pandas DataFrame
  17. df = pd.read_csv(input_file_path)
  18. # Setting the theme for the plots
  19. sns.set_theme(style="ticks")
  20. # Define the clusters
  21. clusters = ["Group"]
  22. cm = 1/2.54
  23. # Adjust the size and DPI for all plots
  24. plt.figure(figsize=(78/3*cm, 11.86/3*cm), dpi=300)
  25. # Define custom palette with colors for each category
  26. custom_palette = {"Sham": "grey", "Stroke": "red"}
  27. # Loop through each cluster and create a catplot
  28. for cluster in clusters:
  29. g = sns.catplot(
  30. data=df, x="TimePointMerged", y="Z_C_PawDragPercent", hue=cluster,
  31. palette=custom_palette, kind="point", height=5, aspect=2.75,
  32. estimator="mean", errorbar=('ci', 95), legend=False,linestyles=["-", "--"]
  33. )
  34. g.despine(left=True)
  35. plt.title(f'Boxplot for {cluster}', fontsize=38.9, fontweight='bold', fontname='Calibri')
  36. # Set x and y labels
  37. plt.xlabel("Time Point", fontsize=38.9, fontweight='bold', fontname='Calibri')
  38. plt.ylabel("Number of hindlimb drops", fontsize=38.9, fontweight='bold', fontname='Calibri')
  39. # Set x and y tick parameters
  40. plt.xticks(fontsize=38.9, fontweight='bold', fontname='Calibri')
  41. plt.yticks(fontsize=38.9, fontweight='bold', fontname='Calibri')
  42. # Access the current axes
  43. ax = plt.gca()
  44. # Set visibility, color, and thickness of axes
  45. ax.spines['top'].set_visible(True)
  46. ax.spines['right'].set_visible(True)
  47. ax.spines['bottom'].set_visible(True)
  48. ax.spines['left'].set_visible(True)
  49. ax.spines['top'].set_color('black')
  50. ax.spines['right'].set_color('black')
  51. ax.spines['bottom'].set_color('black')
  52. ax.spines['left'].set_color('black')
  53. ax.spines['top'].set_linewidth(0) # Set thickness of top spine
  54. ax.spines['right'].set_linewidth(0) # Set thickness of right spine
  55. ax.spines['bottom'].set_linewidth(4) # Set thickness of bottom spine
  56. ax.spines['left'].set_linewidth(4) # Set thickness of left spine
  57. #g.set(ylim=(0, 0))
  58. # Set thickness of ticks
  59. plt.tick_params(axis='both', which='major', width=4, length=11)
  60. # Adjust the thickness of the lines
  61. for line in ax.lines:
  62. line.set_linewidth(5) # Set the desired linewidth
  63. plt.show()