matplotlib comes with tons of fantastic examples. I’m not as familiar with matplotlib as I probably should be, so I often find myself wanting to tinker a bit, but needing to refer to those examples. Since matplotlib comes with such wonderful documentation, I though it would be great to just turn those docs into IPython Notebooks for easy tinkering. That’s probably biting off a bit more than I want to chew at the moment, considering that the matplotlib docs are fairly involved and written in reStructuredText instead of markdown (what the IPython Notebook uses).
Luckily, the IPython Notebook format is so mind-bendingly sane that
I didn’t even need to read any documentation to understand it. So,
instead, I wrote a bit of code that gobbles up matplotlib example
scripts and spits out IPython Notebooks.
The whole notebook is JSON, but I
only want simple things, so I hardcode everything except for the
cells. (After Daniel’s comment below, I started to write my own
JSONEncoder. Then, I realized that I was right about the “it’s all
JSON” thing and rewrote the notebook class). I have a little IPyNB
class that knows how to add cells to itself and spit out the results
as strings and files: