gaitsetpy.eda.visualization
This module contains functions for visualizing the thigh, shank, and trunk acceleration data from the Daphnet dataset. Maintainer : @aharshit123456
TODO :
- Make the thigh, shank, trunk dataframe parent child extraction functions
1''' 2This module contains functions for visualizing the thigh, shank, and trunk acceleration data from the Daphnet dataset. 3Maintainer : @aharshit123456 4 5TODO : 6- Make the thigh, shank, trunk dataframe parent child extraction functions 7 8''' 9 10import matplotlib.pyplot as plt 11import numpy as np 12 13##################################################################################################### 14############################################ FOR DAPHNET ############################################ 15##################################################################################################### 16 17 18def plot_thigh_data(daphnetThigh, daphnetNames, i): 19 """ 20 Plot thigh acceleration data for a specific dataset. 21 Args: 22 daphnetThigh (list): List of DataFrames containing thigh acceleration data. 23 daphnetNames (list): List of dataset names. 24 i (int): Index of the dataset to plot. 25 """ 26 print(daphnetNames[i]) 27 fig, axes = plt.subplots(4, 1, sharex=True, sharey=True, figsize=(20, 16)) 28 fig.suptitle("Thigh Data from " + daphnetNames[i]) 29 plt.xlabel("Time") 30 31 df = daphnetThigh[i] 32 df = df[df.annotations > 0] # Filter out rows with no annotations 33 neg = df[df.annotations == 1] # No freeze 34 pos = df[df.annotations == 2] # Freeze 35 36 # Plot horizontal forward thigh acceleration 37 ax1 = axes[0] 38 ax1.plot(df.thigh_h_fd) 39 ax1.set_ylabel("Horizontal Forward Thigh Acceleration") 40 ax1.scatter(neg.index, neg.thigh_h_fd, c='orange', label="no freeze") 41 ax1.scatter(pos.index, pos.thigh_h_fd, c='purple', label="freeze") 42 ax1.legend() 43 44 # Plot vertical thigh acceleration 45 ax2 = axes[1] 46 ax2.plot(df.thigh_v) 47 ax2.set_ylabel("Vertical Thigh Acceleration") 48 ax2.scatter(neg.index, neg.thigh_v, c='orange', label="no freeze") 49 ax2.scatter(pos.index, pos.thigh_v, c='purple', label="freeze") 50 ax2.legend() 51 52 # Plot horizontal lateral thigh acceleration 53 ax3 = axes[2] 54 ax3.plot(df.thigh_h_l) 55 ax3.set_ylabel("Horizontal Lateral Thigh Acceleration") 56 ax3.scatter(neg.index, neg.thigh_h_l, c='orange', label="no freeze") 57 ax3.scatter(pos.index, pos.thigh_h_l, c='purple', label="freeze") 58 ax3.legend() 59 60 # Plot overall thigh acceleration 61 ax4 = axes[3] 62 ax4.plot(df.thigh) 63 ax4.set_ylabel("Overall Thigh Acceleration") 64 ax4.scatter(neg.index, neg.thigh, c='orange', label="no freeze") 65 ax4.scatter(pos.index, pos.thigh, c='purple', label="freeze") 66 ax4.legend() 67 68 plt.tight_layout() 69 plt.show() 70 71 72def plot_shank_data(daphnetShank, daphnetNames, i): 73 """ 74 Plot shank acceleration data for a specific dataset. 75 Args: 76 daphnetShank (list): List of DataFrames containing shank acceleration data. 77 daphnetNames (list): List of dataset names. 78 i (int): Index of the dataset to plot. 79 """ 80 print(daphnetNames[i]) 81 fig, axes = plt.subplots(4, 1, sharex=True, sharey=True, figsize=(20, 16)) 82 fig.suptitle("Shank Data from " + daphnetNames[i]) 83 plt.xlabel("Time") 84 85 df = daphnetShank[i] 86 df["shank"] = np.sqrt(df["shank_h_l"]**2 + df["shank_v"]**2 + df["shank_h_fd"]**2) 87 df = df[df.annotations > 0] 88 neg = df[df.annotations == 1] 89 pos = df[df.annotations == 2] 90 91 ax1 = axes[0] 92 ax1.plot(df.shank_h_fd) 93 ax1.set_ylabel("Horizontal Forward Shank Acceleration") 94 ax1.scatter(neg.index, neg.shank_h_fd, c='orange', label="no freeze") 95 ax1.scatter(pos.index, pos.shank_h_fd, c='purple', label="freeze") 96 ax1.legend() 97 98 ax2 = axes[1] 99 ax2.plot(df.shank_v) 100 ax2.set_ylabel("Vertical Shank Acceleration") 101 ax2.scatter(neg.index, neg.shank_v, c='orange', label="no freeze") 102 ax2.scatter(pos.index, pos.shank_v, c='purple', label="freeze") 103 ax2.legend() 104 105 ax3 = axes[2] 106 ax3.plot(df.shank_h_l) 107 ax3.set_ylabel("Horizontal Lateral Shank Acceleration") 108 ax3.scatter(neg.index, neg.shank_h_l, c='orange', label="no freeze") 109 ax3.scatter(pos.index, pos.shank_h_l, c='purple', label="freeze") 110 ax3.legend() 111 112 ax4 = axes[3] 113 ax4.plot(df.shank) 114 ax4.set_ylabel("Overall Shank Acceleration") 115 ax4.scatter(neg.index, neg.shank, c='orange', label="no freeze") 116 ax4.scatter(pos.index, pos.shank, c='purple', label="freeze") 117 ax4.legend() 118 119 plt.tight_layout() 120 plt.show() 121 122 123def plot_trunk_data(daphnetTrunk, daphnetNames, i): 124 """ 125 Plot trunk acceleration data for a specific dataset. 126 Args: 127 daphnetTrunk (list): List of DataFrames containing trunk acceleration data. 128 daphnetNames (list): List of dataset names. 129 i (int): Index of the dataset to plot. 130 """ 131 print(daphnetNames[i]) 132 fig, axes = plt.subplots(4, 1, sharex=True, sharey=True, figsize=(20, 16)) 133 fig.suptitle("Trunk Data from " + daphnetNames[i]) 134 plt.xlabel("Time") 135 136 df = daphnetTrunk[i] 137 df["trunk"] = np.sqrt(df["trunk_h_l"]**2 + df["trunk_v"]**2 + df["trunk_h_fd"]**2) 138 df = df[df.annotations > 0] 139 neg = df[df.annotations == 1] 140 pos = df[df.annotations == 2] 141 142 ax1 = axes[0] 143 ax1.plot(df.trunk_h_fd) 144 ax1.set_ylabel("Horizontal Forward Trunk Acceleration") 145 ax1.scatter(neg.index, neg.trunk_h_fd, c='orange', label="no freeze") 146 ax1.scatter(pos.index, pos.trunk_h_fd, c='purple', label="freeze") 147 ax1.legend() 148 149 ax2 = axes[1] 150 ax2.plot(df.trunk_v) 151 ax2.set_ylabel("Vertical Trunk Acceleration") 152 ax2.scatter(neg.index, neg.trunk_v, c='orange', label="no freeze") 153 ax2.scatter(pos.index, pos.trunk_v, c='purple', label="freeze") 154 ax2.legend() 155 156 ax3 = axes[2] 157 ax3.plot(df.trunk_h_l) 158 ax3.set_ylabel("Horizontal Lateral Trunk Acceleration") 159 ax3.scatter(neg.index, neg.trunk_h_l, c='orange', label="no freeze") 160 ax3.scatter(pos.index, pos.trunk_h_l, c='purple', label="freeze") 161 ax3.legend() 162 163 ax4 = axes[3] 164 ax4.plot(df.trunk) 165 ax4.set_ylabel("Overall Trunk Acceleration") 166 ax4.scatter(neg.index, neg.trunk, c='orange', label="no freeze") 167 ax4.scatter(pos.index, pos.trunk, c='purple', label="freeze") 168 ax4.legend() 169 170 plt.tight_layout() 171 plt.show() 172 173 174def plot_all_thigh_data(daphnetThigh, daphnetNames): 175 """Plot thigh acceleration data for all datasets.""" 176 for i in range(len(daphnetThigh)): 177 plot_thigh_data(daphnetThigh, daphnetNames, i) 178 179def plot_all_shank_data(daphnetShank, daphnetNames): 180 """Plot shank acceleration data for all datasets.""" 181 for i in range(len(daphnetShank)): 182 plot_shank_data(daphnetShank, daphnetNames, i) 183 184def plot_all_trunk_data(daphnetTrunk, daphnetNames): 185 """Plot trunk acceleration data for all datasets.""" 186 for i in range(len(daphnetTrunk)): 187 plot_trunk_data(daphnetTrunk, daphnetNames, i) 188 189 190def plot_all_data(daphnetThigh, daphnetShank, daphnetTrunk, daphnetNames, i): 191 """ 192 Plot thigh, shank, and trunk acceleration data for a specific dataset. 193 Args: 194 daphnetThigh (list): List of DataFrames containing thigh acceleration data. 195 daphnetShank (list): List of DataFrames containing shank acceleration data. 196 daphnetTrunk (list): List of DataFrames containing trunk acceleration data. 197 daphnetNames (list): List of dataset names. 198 i (int): Index of the dataset to plot. 199 """ 200 plot_thigh_data(daphnetThigh, daphnetNames, i) 201 plot_shank_data(daphnetShank, daphnetNames, i) 202 plot_trunk_data(daphnetTrunk, daphnetNames, i) 203 204def plot_all_datasets(daphnetThigh, daphnetShank, daphnetTrunk, daphnetNames): 205 """Plot thigh, shank, and trunk acceleration data for all datasets.""" 206 for i in range(len(daphnetThigh)): 207 plot_all_data(daphnetThigh, daphnetShank, daphnetTrunk, daphnetNames, i) 208 209############################################ FOR HAR-UP ############################################ 210 211def plot_sensor_timeseries(harup_df, sensor_col, title=None): 212 """ 213 Plot the time series for a given sensor column in a HAR-UP DataFrame. 214 Args: 215 harup_df (pd.DataFrame): DataFrame containing HAR-UP data. 216 sensor_col (str): Name of the sensor column to plot. 217 title (str, optional): Plot title. 218 """ 219 import matplotlib.pyplot as plt 220 if sensor_col not in harup_df.columns: 221 print(f"Column {sensor_col} not found in DataFrame.") 222 return 223 plt.figure(figsize=(16, 4)) 224 plt.plot(harup_df[sensor_col].values) 225 plt.xlabel("Sample") 226 plt.ylabel(sensor_col) 227 plt.title(title or f"{sensor_col} Time Series") 228 plt.tight_layout() 229 plt.show() 230 231def plot_all_sensors(harup_df, sensor_cols=None, max_cols=4): 232 """ 233 Plot all (or selected) sensor time series for a HAR-UP DataFrame. 234 Args: 235 harup_df (pd.DataFrame): DataFrame containing HAR-UP data. 236 sensor_cols (list, optional): List of sensor columns to plot. If None, plot all numeric columns except metadata. 237 max_cols (int): Number of subplots per row. 238 """ 239 import matplotlib.pyplot as plt 240 import pandas as pd 241 if sensor_cols is None: 242 sensor_cols = [col for col in harup_df.columns if pd.api.types.is_numeric_dtype(harup_df[col]) and col not in ['subject_id', 'activity_id', 'trial_id']] 243 n = len(sensor_cols) 244 nrows = (n + max_cols - 1) // max_cols 245 fig, axes = plt.subplots(nrows, max_cols, figsize=(5*max_cols, 3*nrows), squeeze=False) 246 for i, col in enumerate(sensor_cols): 247 ax = axes[i // max_cols][i % max_cols] 248 ax.plot(harup_df[col].values) 249 ax.set_title(col) 250 ax.set_xlabel("Sample") 251 for j in range(i+1, nrows*max_cols): 252 fig.delaxes(axes[j // max_cols][j % max_cols]) 253 plt.tight_layout() 254 plt.show() 255 256def plot_activity_distribution(harup_df): 257 """ 258 Plot a bar chart of activity label distribution in a HAR-UP DataFrame. 259 Args: 260 harup_df (pd.DataFrame): DataFrame containing HAR-UP data. 261 """ 262 import matplotlib.pyplot as plt 263 if 'activity_label' not in harup_df.columns: 264 print("No 'activity_label' column found.") 265 return 266 counts = harup_df['activity_label'].value_counts().sort_index() 267 plt.figure(figsize=(10, 4)) 268 counts.plot(kind='bar') 269 plt.xlabel("Activity") 270 plt.ylabel("Count") 271 plt.title("Activity Distribution") 272 plt.tight_layout() 273 plt.show()
19def plot_thigh_data(daphnetThigh, daphnetNames, i): 20 """ 21 Plot thigh acceleration data for a specific dataset. 22 Args: 23 daphnetThigh (list): List of DataFrames containing thigh acceleration data. 24 daphnetNames (list): List of dataset names. 25 i (int): Index of the dataset to plot. 26 """ 27 print(daphnetNames[i]) 28 fig, axes = plt.subplots(4, 1, sharex=True, sharey=True, figsize=(20, 16)) 29 fig.suptitle("Thigh Data from " + daphnetNames[i]) 30 plt.xlabel("Time") 31 32 df = daphnetThigh[i] 33 df = df[df.annotations > 0] # Filter out rows with no annotations 34 neg = df[df.annotations == 1] # No freeze 35 pos = df[df.annotations == 2] # Freeze 36 37 # Plot horizontal forward thigh acceleration 38 ax1 = axes[0] 39 ax1.plot(df.thigh_h_fd) 40 ax1.set_ylabel("Horizontal Forward Thigh Acceleration") 41 ax1.scatter(neg.index, neg.thigh_h_fd, c='orange', label="no freeze") 42 ax1.scatter(pos.index, pos.thigh_h_fd, c='purple', label="freeze") 43 ax1.legend() 44 45 # Plot vertical thigh acceleration 46 ax2 = axes[1] 47 ax2.plot(df.thigh_v) 48 ax2.set_ylabel("Vertical Thigh Acceleration") 49 ax2.scatter(neg.index, neg.thigh_v, c='orange', label="no freeze") 50 ax2.scatter(pos.index, pos.thigh_v, c='purple', label="freeze") 51 ax2.legend() 52 53 # Plot horizontal lateral thigh acceleration 54 ax3 = axes[2] 55 ax3.plot(df.thigh_h_l) 56 ax3.set_ylabel("Horizontal Lateral Thigh Acceleration") 57 ax3.scatter(neg.index, neg.thigh_h_l, c='orange', label="no freeze") 58 ax3.scatter(pos.index, pos.thigh_h_l, c='purple', label="freeze") 59 ax3.legend() 60 61 # Plot overall thigh acceleration 62 ax4 = axes[3] 63 ax4.plot(df.thigh) 64 ax4.set_ylabel("Overall Thigh Acceleration") 65 ax4.scatter(neg.index, neg.thigh, c='orange', label="no freeze") 66 ax4.scatter(pos.index, pos.thigh, c='purple', label="freeze") 67 ax4.legend() 68 69 plt.tight_layout() 70 plt.show()
Plot thigh acceleration data for a specific dataset. Args: daphnetThigh (list): List of DataFrames containing thigh acceleration data. daphnetNames (list): List of dataset names. i (int): Index of the dataset to plot.
73def plot_shank_data(daphnetShank, daphnetNames, i): 74 """ 75 Plot shank acceleration data for a specific dataset. 76 Args: 77 daphnetShank (list): List of DataFrames containing shank acceleration data. 78 daphnetNames (list): List of dataset names. 79 i (int): Index of the dataset to plot. 80 """ 81 print(daphnetNames[i]) 82 fig, axes = plt.subplots(4, 1, sharex=True, sharey=True, figsize=(20, 16)) 83 fig.suptitle("Shank Data from " + daphnetNames[i]) 84 plt.xlabel("Time") 85 86 df = daphnetShank[i] 87 df["shank"] = np.sqrt(df["shank_h_l"]**2 + df["shank_v"]**2 + df["shank_h_fd"]**2) 88 df = df[df.annotations > 0] 89 neg = df[df.annotations == 1] 90 pos = df[df.annotations == 2] 91 92 ax1 = axes[0] 93 ax1.plot(df.shank_h_fd) 94 ax1.set_ylabel("Horizontal Forward Shank Acceleration") 95 ax1.scatter(neg.index, neg.shank_h_fd, c='orange', label="no freeze") 96 ax1.scatter(pos.index, pos.shank_h_fd, c='purple', label="freeze") 97 ax1.legend() 98 99 ax2 = axes[1] 100 ax2.plot(df.shank_v) 101 ax2.set_ylabel("Vertical Shank Acceleration") 102 ax2.scatter(neg.index, neg.shank_v, c='orange', label="no freeze") 103 ax2.scatter(pos.index, pos.shank_v, c='purple', label="freeze") 104 ax2.legend() 105 106 ax3 = axes[2] 107 ax3.plot(df.shank_h_l) 108 ax3.set_ylabel("Horizontal Lateral Shank Acceleration") 109 ax3.scatter(neg.index, neg.shank_h_l, c='orange', label="no freeze") 110 ax3.scatter(pos.index, pos.shank_h_l, c='purple', label="freeze") 111 ax3.legend() 112 113 ax4 = axes[3] 114 ax4.plot(df.shank) 115 ax4.set_ylabel("Overall Shank Acceleration") 116 ax4.scatter(neg.index, neg.shank, c='orange', label="no freeze") 117 ax4.scatter(pos.index, pos.shank, c='purple', label="freeze") 118 ax4.legend() 119 120 plt.tight_layout() 121 plt.show()
Plot shank acceleration data for a specific dataset. Args: daphnetShank (list): List of DataFrames containing shank acceleration data. daphnetNames (list): List of dataset names. i (int): Index of the dataset to plot.
124def plot_trunk_data(daphnetTrunk, daphnetNames, i): 125 """ 126 Plot trunk acceleration data for a specific dataset. 127 Args: 128 daphnetTrunk (list): List of DataFrames containing trunk acceleration data. 129 daphnetNames (list): List of dataset names. 130 i (int): Index of the dataset to plot. 131 """ 132 print(daphnetNames[i]) 133 fig, axes = plt.subplots(4, 1, sharex=True, sharey=True, figsize=(20, 16)) 134 fig.suptitle("Trunk Data from " + daphnetNames[i]) 135 plt.xlabel("Time") 136 137 df = daphnetTrunk[i] 138 df["trunk"] = np.sqrt(df["trunk_h_l"]**2 + df["trunk_v"]**2 + df["trunk_h_fd"]**2) 139 df = df[df.annotations > 0] 140 neg = df[df.annotations == 1] 141 pos = df[df.annotations == 2] 142 143 ax1 = axes[0] 144 ax1.plot(df.trunk_h_fd) 145 ax1.set_ylabel("Horizontal Forward Trunk Acceleration") 146 ax1.scatter(neg.index, neg.trunk_h_fd, c='orange', label="no freeze") 147 ax1.scatter(pos.index, pos.trunk_h_fd, c='purple', label="freeze") 148 ax1.legend() 149 150 ax2 = axes[1] 151 ax2.plot(df.trunk_v) 152 ax2.set_ylabel("Vertical Trunk Acceleration") 153 ax2.scatter(neg.index, neg.trunk_v, c='orange', label="no freeze") 154 ax2.scatter(pos.index, pos.trunk_v, c='purple', label="freeze") 155 ax2.legend() 156 157 ax3 = axes[2] 158 ax3.plot(df.trunk_h_l) 159 ax3.set_ylabel("Horizontal Lateral Trunk Acceleration") 160 ax3.scatter(neg.index, neg.trunk_h_l, c='orange', label="no freeze") 161 ax3.scatter(pos.index, pos.trunk_h_l, c='purple', label="freeze") 162 ax3.legend() 163 164 ax4 = axes[3] 165 ax4.plot(df.trunk) 166 ax4.set_ylabel("Overall Trunk Acceleration") 167 ax4.scatter(neg.index, neg.trunk, c='orange', label="no freeze") 168 ax4.scatter(pos.index, pos.trunk, c='purple', label="freeze") 169 ax4.legend() 170 171 plt.tight_layout() 172 plt.show()
Plot trunk acceleration data for a specific dataset. Args: daphnetTrunk (list): List of DataFrames containing trunk acceleration data. daphnetNames (list): List of dataset names. i (int): Index of the dataset to plot.
175def plot_all_thigh_data(daphnetThigh, daphnetNames): 176 """Plot thigh acceleration data for all datasets.""" 177 for i in range(len(daphnetThigh)): 178 plot_thigh_data(daphnetThigh, daphnetNames, i)
Plot thigh acceleration data for all datasets.
180def plot_all_shank_data(daphnetShank, daphnetNames): 181 """Plot shank acceleration data for all datasets.""" 182 for i in range(len(daphnetShank)): 183 plot_shank_data(daphnetShank, daphnetNames, i)
Plot shank acceleration data for all datasets.
185def plot_all_trunk_data(daphnetTrunk, daphnetNames): 186 """Plot trunk acceleration data for all datasets.""" 187 for i in range(len(daphnetTrunk)): 188 plot_trunk_data(daphnetTrunk, daphnetNames, i)
Plot trunk acceleration data for all datasets.
191def plot_all_data(daphnetThigh, daphnetShank, daphnetTrunk, daphnetNames, i): 192 """ 193 Plot thigh, shank, and trunk acceleration data for a specific dataset. 194 Args: 195 daphnetThigh (list): List of DataFrames containing thigh acceleration data. 196 daphnetShank (list): List of DataFrames containing shank acceleration data. 197 daphnetTrunk (list): List of DataFrames containing trunk acceleration data. 198 daphnetNames (list): List of dataset names. 199 i (int): Index of the dataset to plot. 200 """ 201 plot_thigh_data(daphnetThigh, daphnetNames, i) 202 plot_shank_data(daphnetShank, daphnetNames, i) 203 plot_trunk_data(daphnetTrunk, daphnetNames, i)
Plot thigh, shank, and trunk acceleration data for a specific dataset. Args: daphnetThigh (list): List of DataFrames containing thigh acceleration data. daphnetShank (list): List of DataFrames containing shank acceleration data. daphnetTrunk (list): List of DataFrames containing trunk acceleration data. daphnetNames (list): List of dataset names. i (int): Index of the dataset to plot.
205def plot_all_datasets(daphnetThigh, daphnetShank, daphnetTrunk, daphnetNames): 206 """Plot thigh, shank, and trunk acceleration data for all datasets.""" 207 for i in range(len(daphnetThigh)): 208 plot_all_data(daphnetThigh, daphnetShank, daphnetTrunk, daphnetNames, i)
Plot thigh, shank, and trunk acceleration data for all datasets.
212def plot_sensor_timeseries(harup_df, sensor_col, title=None): 213 """ 214 Plot the time series for a given sensor column in a HAR-UP DataFrame. 215 Args: 216 harup_df (pd.DataFrame): DataFrame containing HAR-UP data. 217 sensor_col (str): Name of the sensor column to plot. 218 title (str, optional): Plot title. 219 """ 220 import matplotlib.pyplot as plt 221 if sensor_col not in harup_df.columns: 222 print(f"Column {sensor_col} not found in DataFrame.") 223 return 224 plt.figure(figsize=(16, 4)) 225 plt.plot(harup_df[sensor_col].values) 226 plt.xlabel("Sample") 227 plt.ylabel(sensor_col) 228 plt.title(title or f"{sensor_col} Time Series") 229 plt.tight_layout() 230 plt.show()
Plot the time series for a given sensor column in a HAR-UP DataFrame. Args: harup_df (pd.DataFrame): DataFrame containing HAR-UP data. sensor_col (str): Name of the sensor column to plot. title (str, optional): Plot title.
232def plot_all_sensors(harup_df, sensor_cols=None, max_cols=4): 233 """ 234 Plot all (or selected) sensor time series for a HAR-UP DataFrame. 235 Args: 236 harup_df (pd.DataFrame): DataFrame containing HAR-UP data. 237 sensor_cols (list, optional): List of sensor columns to plot. If None, plot all numeric columns except metadata. 238 max_cols (int): Number of subplots per row. 239 """ 240 import matplotlib.pyplot as plt 241 import pandas as pd 242 if sensor_cols is None: 243 sensor_cols = [col for col in harup_df.columns if pd.api.types.is_numeric_dtype(harup_df[col]) and col not in ['subject_id', 'activity_id', 'trial_id']] 244 n = len(sensor_cols) 245 nrows = (n + max_cols - 1) // max_cols 246 fig, axes = plt.subplots(nrows, max_cols, figsize=(5*max_cols, 3*nrows), squeeze=False) 247 for i, col in enumerate(sensor_cols): 248 ax = axes[i // max_cols][i % max_cols] 249 ax.plot(harup_df[col].values) 250 ax.set_title(col) 251 ax.set_xlabel("Sample") 252 for j in range(i+1, nrows*max_cols): 253 fig.delaxes(axes[j // max_cols][j % max_cols]) 254 plt.tight_layout() 255 plt.show()
Plot all (or selected) sensor time series for a HAR-UP DataFrame. Args: harup_df (pd.DataFrame): DataFrame containing HAR-UP data. sensor_cols (list, optional): List of sensor columns to plot. If None, plot all numeric columns except metadata. max_cols (int): Number of subplots per row.
257def plot_activity_distribution(harup_df): 258 """ 259 Plot a bar chart of activity label distribution in a HAR-UP DataFrame. 260 Args: 261 harup_df (pd.DataFrame): DataFrame containing HAR-UP data. 262 """ 263 import matplotlib.pyplot as plt 264 if 'activity_label' not in harup_df.columns: 265 print("No 'activity_label' column found.") 266 return 267 counts = harup_df['activity_label'].value_counts().sort_index() 268 plt.figure(figsize=(10, 4)) 269 counts.plot(kind='bar') 270 plt.xlabel("Activity") 271 plt.ylabel("Count") 272 plt.title("Activity Distribution") 273 plt.tight_layout() 274 plt.show()
Plot a bar chart of activity label distribution in a HAR-UP DataFrame. Args: harup_df (pd.DataFrame): DataFrame containing HAR-UP data.