Rendering a 3D Rubik's Cube with Matplotlib
How to draw a fully interactive Rubik’s cube using Poly3DCollection, handle keyboard events for face rotations, and integrate the Kociemba two-phase solver.
Why Matplotlib for a Rubik’s Cube?
Rubik’s cube visualizations typically use OpenGL, Three.js, or a game engine. Using matplotlib’s
mpl_toolkits.mplot3dis unconventional. It’s designed for scientific plotting, not real-time 3D interaction. But it has one huge advantage: zero dependencies beyond what you already have for data visualization. No WebGL, no GPU shaders, no build pipeline. Justpip install matplotliband you have a working 3D cube.Building a Physics Simulation Engine in Python
How the physics_modeling package is architected: base classes, numerical integrators, separation of physics from visualization, and property-based testing.
The Core Abstraction
Every physics simulation answers the same question: given a system’s current state, what is its state at the next instant? Whether you’re modeling a spring, an epidemic, or a galaxy of gravitating bodies, the computation follows one pattern: compute derivatives, advance time, repeat.
The
physics_modelingpackage encodes this pattern in aSimulationbase class:Modernizing Legacy Code: From 2004 VPython to Python 3.14
Taking old college physics simulations written twenty years ago and getting them running on modern Python.
The Time Capsule
In 2004, I was a student at The Evergreen State College in a program called Modeling Motion. We wrote Python simulations of physics phenomena (springs, gravity, epidemics, particle collisions) using a library called VPython. I was learning physics and programming simultaneously, translating equations of motion into running code for the first time.
Building Space MUD: A Text Game About Robots on a Space Station
The premise is simple: you wake up on a broken space station. You don’t remember anything. You start exploring, picking up items, talking to other units, repairing systems. And at some point it clicks: you’re not a person. You’re a robot. The whole game uses mechanical language from the start. Your health is “integrity.” You don’t sleep, you go idle. When you die, it’s an “emergency reboot.” The station doesn’t call you a crew member. It calls you a unit.
Who Was Aboard the Titanic? Clustering Passengers (and Testing Whether It Helps Prediction)
Everyone who has ever touched a Kaggle dataset has tried to predict who survived the Titanic. It’s the “Hello World” of machine learning: load the data, tune a model, submit a CSV, feel clever. I wanted to ask a different question.
Not “who survived?” but Seinfeld’s age-old question of “who are these people?”
Prediction treats the passengers as rows in a matrix. Clustering treats them as human beings who fall into natural groups: the wealthy elite, young workers, immigrant families, people traveling alone. Those groups fall out of the data on their own, without anyone labeling them. Then you overlay survival on top and the story gets a lot more human than any accuracy score.
How Kaggle submissions actually work (CSV, code comps, and not wasting your daily budget)
Submitting to Kaggle sounds trivial until your first CSV gets rejected for a reason the error message won’t explain. Here’s how the two formats work and how not to burn your limited daily submissions on nothing.
CSV submissions
Most competitions want a CSV with an ID column and one or more prediction columns. Titanic, for example:
PassengerId,Survived 892,0 893,1 894,0 ...The rules that actually bite:
- Column names have to match the sample submission file exactly.
- Row count has to equal the test set. Not one more, not one fewer.
- No extra columns, and no index column (this is the one that gets everyone).
Code Competition submissions
Some competitions make you submit a notebook that generates predictions at runtime instead of a finished CSV. In those:
Getting the Kaggle CLI working without the usual headaches
Doing Kaggle from the terminal instead of clicking around the website is so much nicer once it’s set up, but the first-time setup has a couple of spots that trip everyone (me included). Here’s the whole thing, including the errors you’ll probably hit.
Install it
pip install kaggleThat gives you the
kagglecommand for pulling data, submitting predictions, and browsing competitions without leaving the terminal.Hook up your credentials
- Log in at kaggle.com/settings
- Find the API section and click Create New Token
- A
kaggle.jsonfile downloads. That’s your credentials, so don’t commit it anywhere. - Move it where the CLI expects:
- Linux/macOS:
~/.kaggle/kaggle.json - Windows:
C:\Users\<username>\.kaggle\kaggle.json
- Linux/macOS:
- On Linux/macOS, lock down the permissions:
chmod 600 ~/.kaggle/kaggle.json
The commands you’ll actually use
Command What it does kaggle competitions listBrowse active competitions kaggle competitions download -c titanicDownload competition data kaggle competitions submit -c titanic -f submission.csv -m "message"Submit predictions kaggle competitions submissions -c titanicSee your submission history kaggle datasets list -s "keyword"Search public datasets When it breaks (and it will, once)
- “Could not find kaggle.json”: the file isn’t in
~/.kaggle/(or%USERPROFILE%\.kaggle\on Windows). That’s almost always it. - “403 Forbidden”: you haven’t accepted the competition rules on the website yet. Go click the button, then try again.
- “401 Unauthorized”: your API token expired or got revoked. Regenerate it and swap in the new
kaggle.json. - Timeouts: usually just the Kaggle API having a slow moment. Check your connection and retry.
If you want to confirm everything’s wired up, run
python scripts/verify_kaggle_cli.pyand it’ll check the setup for you.Building an AI-Assisted Kaggle Toolkit
I got tired of the standard Kaggle workflow. Open a notebook, import pandas, start typing
.describe(), throw some models at the wall. It works, but you don’t learn much, and three months later you can’t remember why you chose XGBoost over Random Forest.So I built a toolkit that forces a better process: research first, then model. Document everything. Produce educational content as a natural byproduct of doing the work.