add athiras code
This commit is contained in:
73
scripts/plot_multi_bars_athira.py
Normal file
73
scripts/plot_multi_bars_athira.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
df = pd.read_excel('/content/data (1).xlsx')
|
||||
device_id_to_plot = 'HCV-000-5003' # Replace with the desired device ID
|
||||
df_filtered = df[df['DEVICE_ID'] == device_id_to_plot]
|
||||
grouped = df_filtered.groupby('USER_ID')
|
||||
|
||||
if not df_filtered.empty:
|
||||
|
||||
led_types = ['Sample', 'Buffer']
|
||||
num_leds = 4
|
||||
user_ids = list(grouped.groups.keys())
|
||||
|
||||
num_groups = len(user_ids) // 5 + (1 if len(user_ids) % 5 != 0 else 0)
|
||||
user_id_groups = [user_ids[i*5:(i+1)*5] for i in range(num_groups)]
|
||||
|
||||
# Create subplots for Sample and Buffer
|
||||
fig, axs = plt.subplots(num_groups, 2, figsize=(12, 5*num_groups), sharex=True, gridspec_kw={'hspace': 0.5})
|
||||
colormap = plt.cm.get_cmap('tab10')
|
||||
|
||||
for i, group_ids in enumerate(user_id_groups):
|
||||
group_data = [grouped.get_group(user_id) for user_id in group_ids]
|
||||
|
||||
for j, led_type in enumerate(led_types):
|
||||
led_values = [[] for _ in range(num_leds)]
|
||||
|
||||
for user_group in group_data:
|
||||
led_vals_per_user = [[] for _ in range(num_leds)]
|
||||
|
||||
for k in range(1, num_leds + 1):
|
||||
led_values_per_user = user_group[f'LED{k}_{led_type}']
|
||||
led_vals_per_user[k - 1].extend(led_values_per_user)
|
||||
|
||||
for led_num in range(num_leds):
|
||||
led_values[led_num].extend(led_vals_per_user[led_num])
|
||||
|
||||
# Plot Sample and Buffer values for each LED
|
||||
x = np.arange(len(group_ids))
|
||||
bar_width = 0.15 # Adjust bar width
|
||||
for led_num in range(num_leds):
|
||||
axs[i, j].bar(x + led_num * bar_width, led_values[led_num][:len(group_ids)], width=bar_width, color=colormap(led_num), label=f'LED {led_num + 1}')
|
||||
|
||||
|
||||
axs[i, j].set_ylabel('Value')
|
||||
axs[i, j].legend()
|
||||
|
||||
|
||||
axs[i, j].set_xticks(x + (num_leds - 1) * bar_width / 2)
|
||||
axs[i, j].set_xticklabels(group_ids, rotation=45, ha='right')
|
||||
|
||||
|
||||
axs[-1, j].set_xlabel('USER_ID')
|
||||
|
||||
#Assigning user id
|
||||
for i, group_ids in enumerate(user_id_groups[:-1]): # Exclude the last group
|
||||
for idx, user_id in enumerate(group_ids):
|
||||
axs[i, 0].text(idx, -0.2, user_id, ha='center', va='center', rotation=-45, fontsize=8)
|
||||
axs[i, 1].text(idx, -0.2, user_id, ha='center', va='center', rotation=-45, fontsize=8)
|
||||
|
||||
last_group_ids = user_id_groups[-1][:-3]
|
||||
for idx, user_id in enumerate(last_group_ids):
|
||||
axs[-1, 0].text(idx, -0.2, user_id, ha='center', va='center', rotation=-45, fontsize=8)
|
||||
axs[-1, 1].text(idx, -0.2, user_id, ha='center', va='center', rotation=-45, fontsize=8)
|
||||
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
else:
|
||||
print(f"No data points found for Device ID: {device_id_to_plot}")
|
||||
|
||||
Reference in New Issue
Block a user