Skip to content

Instantly share code, notes, and snippets.

@lxgr
Created July 20, 2025 01:30
Show Gist options
  • Select an option

  • Save lxgr/694a72d9fb64d88c8650a117d418420d to your computer and use it in GitHub Desktop.

Select an option

Save lxgr/694a72d9fb64d88c8650a117d418420d to your computer and use it in GitHub Desktop.
Plot conversation stats by month from ChatGPT export JSON.
#!/usr/bin/env uv run
# /// script
# dependencies = ["matplotlib"]
# ///
"""
Plot conversation stats by month from ChatGPT export JSON.
Usage: ./plot.py conversations.json
"""
import json, matplotlib.pyplot as plt, sys, subprocess
jq_command = [
'jq',
'''
[ .[] | select(has("create_time"))
| { month: (.create_time | strftime("%Y-%m")) } ]
| group_by(.month)
| map({ month: .[0].month, count: length })
| sort_by(.month)
''',
sys.argv[1]
]
result = subprocess.run(jq_command, capture_output=True, text=True)
if result.returncode != 0:
print(f"jq error: {result.stderr}", file=sys.stderr)
sys.exit(1)
data = json.loads(result.stdout)
months, counts = [], []
for row in data:
months.append(row["month"])
counts.append(int(row["count"]))
plt.bar(months, counts)
plt.xticks(rotation=45, ha='right')
plt.ylabel("Count")
plt.title("Conversations per Month")
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment