Advertisement
El_Chaderino

Radar Chart Example for EEG Visualization

Sep 16th, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. # Create radar chart function for plotting the EEG metrics
  5. def create_radar_chart(values, labels, title):
  6.     # Number of variables we're plotting.
  7.     num_vars = len(labels)
  8.  
  9.     # Compute angle of each axis on the plot (360 degrees distributed over the number of variables).
  10.     angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist()
  11.  
  12.     # Repeat the first value to close the circular chart
  13.     values += values[:1]
  14.     angles += angles[:1]
  15.  
  16.     # Set up the radar plot
  17.     fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
  18.  
  19.     ax.fill(angles, values, color='blue', alpha=0.25)
  20.     ax.plot(angles, values, color='blue', linewidth=2)
  21.  
  22.     # Labels for each axis
  23.     ax.set_yticklabels([])
  24.     ax.set_xticks(angles[:-1])
  25.     ax.set_xticklabels(labels)
  26.  
  27.     # Add title and make it look nicer
  28.     ax.set_title(title, size=20, color='black', y=1.1)
  29.     plt.show()
  30.  
  31. # Values and labels for each site (CZ, O1, F3, F4)
  32. cz_values = [8.0, 2.9, 5.6, 0.53, 8.2, 5.1, 5.7, 0.85, 10.1]  # Example values for CZ
  33. o1_values = [7.9, 2.5, 4.8, 0.50, 8.0, 4.8, 5.0, 0.88, 9.8]  # Example values for O1
  34. f3_values = [8.5, 3.0, 6.0, 0.54, 8.5, 5.0, 5.5, 0.90, 10.5]  # Example values for F3
  35. f4_values = [8.3, 3.1, 6.2, 0.56, 8.4, 5.2, 5.8, 0.89, 10.3]  # Example values for F4
  36.  
  37. labels = ["Delta 2 Hz", "HiBeta Amplitude", "Beta Amplitude", "HiBeta/Beta",
  38.           "Sum HiBeta + Beta", "LoAlpha Amplitude", "HiAlpha Amplitude",
  39.           "LoAlpha/HiAlpha", "Alpha Peak Freq"]
  40.  
  41. # Create radar charts for each site
  42. create_radar_chart(cz_values, labels, "CZ Site Radar Chart")
  43. create_radar_chart(o1_values, labels, "O1 Site Radar Chart")
  44. create_radar_chart(f3_values, labels, "F3 Site Radar Chart")
  45. create_radar_chart(f4_values, labels, "F4 Site Radar Chart")
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement