matplotlib/matplotlib — pull request #2588 by pwuertz (2013-11-09 17:05:52+00:00)
Title: Refactor mechanism for saving files.

I was trying to fix `bbox_inches` support for backend_pgf (issue #2586). However, I can't do this properly since `tight_bbox` needs to know if a backend uses figure.dpi or fixed 72dpi. Right now it derives this information from the file-type, which doesn't really work since different backends may be used for the same type. To fix this problem I need to know which backend is used when saving files in `FigureCanvasBase.print_figure()`.

This required some major changes. I'll break them down to the following steps:
- Removed print_ methods from `FigureCanvasBase` and thus a lot of code duplication. Moved `print_jpeg` and `print_tiff` to the Agg backend where they are actually implemented.
- Picked up the rather dormant system for mapping file-types to backends in `backend_bases` and made it the default reference for finding an appropriate FigureCanvas for a given file type. FigureCanvas is now a canonical alias in each backend. Deferred imports of those are now handled centrally in `get_registered_canvas_class()`.
- Default format-to-backend mappings can be added or changed by `register_backend()`. This is also reflected in the save dialogues of graphical user interfaces.

The `print_figure()` method now works in the following way:
- Check if the current FigureCanvas supports the requested file type
- Check if there is a registered FigureCanvas for handling the file type
- Else, report file format error.

Most code parts I modified came from @mdboom and @leejjoon, so I humbly ask you for your opinions.