I have a dataset which consists of data gathered from experiments from various participants done over 3 days.
I managed to plot the data for each participant on a seperate plot for each experiment succefully using the following code:
by_part = p1.groupby('participant_id')
for name, group in by_part:
byexp_num = p1.groupby('exp_num')
fig, axs = plt.subplots(figsize=(len(byexp_num), 5), nrows=2, ncols=(len(byexp_num)//2)+ (len(byexp_num) % 2 > 0)) #as there are 2 rows, the column is by the length of the experiments divided by 2 plus the modulo of the same operation to account for odd numbers
plt.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.8, wspace=0.4, hspace=0.4)
fig.suptitle('Participant {}'.format(name), fontsize=20)
subplot_targets = zip(byexp_num.groups.keys(), axs.flatten())
for key, ax in subplot_targets:
ax.plot(byexp_num.get_group(key).rn_norm, byexp_num.get_group(key).scale_data)
ax.set_ylabel('Scale Data')
ax.set_title('Experiment {}'.format(key+1))
But when I try to group the data in days and plot multiple experiments on the same graph for each day there is a problem with how the graphs are displayed. The data is grouped succesffuly, but it joins the all the experiments together. i.e the line continues from the last datapoint of the experiment to the next so instead of showing n seperate lines in each plot, it shows 1 continuous one. I am not sure about what im doing wrong.
by_part = p1.groupby('participant_id')
p1 = df_all[(df_all['participant_id']== 1)]
by_part = p1.groupby('participant_id')
for name, group in by_part:
by_day = p1.groupby('day')
fig, axs = plt.subplots(figsize=(30, 5), nrows=1, ncols=(len(by_day)))
fig.suptitle('Participant {}'.format(name), fontsize=20)
subplot_targets = zip(by_day.groups.keys(), axs.flatten())
for key, ax in subplot_targets:
ax.plot(by_day.get_group(key).rn, by_day.get_group(key).scale_data)
ax.set_ylabel('Scale Data')
ax.set_title('Day {}'.format(key))
ax.legend(p1['exp_num'])
Here is the graph it displays. Plots
EDIT Adding dataframe as requested by GalacticPonderer

