Skip to content

Instantly share code, notes, and snippets.

@adrianlzt
Created October 23, 2025 07:36
Show Gist options
  • Save adrianlzt/c8867cd072ba56b94fae5acc76ec8052 to your computer and use it in GitHub Desktop.
Save adrianlzt/c8867cd072ba56b94fae5acc76ec8052 to your computer and use it in GitHub Desktop.
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "pandas",
# "matplotlib",
# ]
# ///
import pandas as pd
import matplotlib.pyplot as plt
import sys
def create_graph(csv_path):
"""
Generates a PNG graph from a CSV file containing timestamp and frame number data.
Args:
csv_path (str): The path to the input CSV file.
"""
try:
print(f"Reading data from {csv_path}...")
data = pd.read_csv(csv_path, header=None, names=[
"timestamp", "frame_number"])
# Calculate time since the first packet
data["relative_time"] = data["timestamp"] - data["timestamp"].iloc[0]
print("Generating graph...")
plt.figure(figsize=(12, 6))
plt.plot(data["relative_time"], data["frame_number"])
plt.xlabel("Time (seconds since first packet)")
plt.ylabel("Frame Number")
plt.title("Frame Number vs. Time")
plt.grid(True)
output_path = csv_path.replace(".csv", ".png")
plt.savefig(output_path)
print(f"Graph saved to {output_path}")
except FileNotFoundError:
print(f"Error: The file '{csv_path}' was not found.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python create_graph.py <path_to_csv_file>")
else:
create_graph(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment