1 · Grouping with `groupby`

1.1 Explanation

You can plot both eyes on the same axes by splitting your original DataFrame by the eye column.

Matplotlib will draw both lines on the same figure, and you add a legend so you can tell them apart.

1.2 Code Example

import matplotlib.pyplot as plt
create a new figure + axis

fig, ax = plt.subplots()

loop through left/right groups

for eye_label, df_eye in eyemovementDF.groupby("eye"):
# plot x‐coordinate
ax.plot(
df_eye["timestamp"],
df_eye["px"],
label=f"{eye_label.capitalize()} Eye – X",
linewidth=2
)
# plot y‐coordinate with a dashed line
ax.plot(
df_eye["timestamp"],
df_eye["py"],
label=f"{eye_label.capitalize()} Eye – Y",
linestyle="--"
)

labels and legend

ax.set_xlabel("Timestamp")
ax.set_ylabel("Pixel Position")
ax.legend()
plt.show()

2 · Pivoting for Direct Comparison

2.1 Explanation

If you prefer one wide DataFrame where left- and right-eye positions are side by side, use pivot:

You get a DataFrame with a MultiIndex on the columns, letting you call e.g. df_pivot["px"]["left"] and df_pivot["px"]["right"] in one go.

2.2 Code Example

import matplotlib.pyplot as plt
pivot the DataFrame

df_pivot = eyemovementDF.pivot(
index="timestamp",
columns="eye",
values=["px", "py"]
)

plot left vs. right X‐positions over time

fig, ax = plt.subplots()
ax.plot(
df_pivot.index,
df_pivot["px"]["left"],
label="Left Eye – X",
linewidth=2
)
ax.plot(
df_pivot.index,
df_pivot["px"]["right"],
label="Right Eye – X",
linewidth=2
)
ax.set_xlabel("Timestamp")
ax.set_ylabel("X Position")
ax.legend()
plt.show()

and similarly for Y if you wish

fig, ay = plt.subplots()

ay.plot(df_pivot.index, df_pivot["py"]["left"], label="Left – Y")

ay.plot(df_pivot.index, df_pivot["py"]["right"], label="Right – Y", linestyle="--")

ay.set_xlabel("Timestamp")

ay.set_ylabel("Y Position")

ay.legend()

plt.show()

3 · Using Your Merged DataFrame

3.1 Explanation

Since you already have merge from pd.merge(leftEye, rightEye, on="timestamp"), you can plot its suffixed columns directly:

3.2 Code Example

import matplotlib.pyplot as plt
fig, ax = plt.subplots()

left‐eye X vs right‐eye X

ax.plot(
merge["timestamp"],
merge["px_x"],
label="Left Eye – X",
linewidth=2
)
ax.plot(
merge["timestamp"],
merge["px_y"],
label="Right Eye – X",
linewidth=2
)

ax.set_xlabel("Timestamp")
ax.set_ylabel("X Position")
ax.legend()
plt.show()