Initial rework of gen_gallery.py

* Creates a toc at the top of the gallery page
* entries are created by a list of sub-directories
* examples from each sub-dir is sectioned
suppress exception upon quitting with qt4agg on osx
Add a link to matplotlib questions on stackoverflow.
Fix writing pdf on stdout

Writing on file-like objects broke object cross-references if
anything else had been written on the same stream before. On Linux
writing on sys.stdout failed because sys.stdout.tell() raises
an error; this is worked around by using a BytesIO object.
BUG: Mask nans in fill_between(x)
STY: Remove unused variables and import.
Add What's New section for Python 3.x support.  Address #1087 in part.
Create a config dir in `tempfile.gettempdir()` if the default location(s) are not writable.
Update docstring to reflect reality.
Use np.ma.masked_invalid to mask NaNs.
Fix formatter reset when twin{x,y}() is called
Merge pull request #1140 from tonysyu/fill_between-fix-nan

BUG: Fix fill_between when NaN values are present
Merge branch 'read-only-directory' of git://github.com/mdboom/matplotlib into mdboom-read-only-directory
update docstrings and faq for modified config directory strategy
Fix invalid transformation in InvertedSymmetricalLogTransform.
Clarify which backends do and don't work.
Merge pull request #1130 from jkseppan/pdf-on-stdout

Fix writing pdf on stdout
for interpolation='none', the affine matrix is calculated in the display coordinate
Add Phil Elson's percentage histogram example
Checkable pan/zoom buttons for QT NavigationToolbar