Refactor mechanism for saving files.#2588
Refactor mechanism for saving files.#2588mdboom merged 2 commits intomatplotlib:masterfrom pwuertz:print_refactor
Conversation
|
Looks good to me. I think this really simplifies things. It appears that importlib is not available on Python 2.6, so we'll have to find a way to include backports of the stuff we need there (as we already do for some parts of |
lib/matplotlib/backend_bases.py
Outdated
There was a problem hiding this comment.
I'm not sure how comfortably this method name sits with me. Since it is private, I'd be happy to let that slip for a decent 1liner docstring. 😄
There was a problem hiding this comment.
Yea, I kind of tried to keep the naming similar to their previous counterparts so it's more obvious what I'm doing. But you're right, I'm going to change that :)
|
The documentation will need to change for backend bases (you must now explicitly have a FigureCanvas alias. Non matplotlib backends (such as IPython's) are probably going to break as a result. Other than that 👍 - this is a really beneficial change. Thanks @pwuertz |
|
@pelson, I didn't find any good place to document this new |
|
@pelson Do you have a suggestion where this could/should be documented? I guess a documentation and some examples regarding the file-format-register-functionality would be nice too. |
Move all print_ methods to their backends. Manage default format-to-backend mappings in backend_bases. print_figure() can now determine the backend for saving figures. Remove print_ code duplication, add canonical FigureCanvas names.
|
@pelson: I think I found a nice place for adding some documentation, an example is in the |
|
I was thinking the @mdboom - I support this change, but it is sufficiently big that I'd like a second opinion. 👍 |
|
I agree, this really simplifies things. Merging. |
Refactor mechanism for saving files.
I was trying to fix
bbox_inchessupport for backend_pgf (issue #2586). However, I can't do this properly sincetight_bboxneeds 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 inFigureCanvasBase.print_figure().This required some major changes. I'll break them down to the following steps:
FigureCanvasBaseand thus a lot of code duplication. Movedprint_jpegandprint_tiffto the Agg backend where they are actually implemented.backend_basesand 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 inget_registered_canvas_class().register_backend(). This is also reflected in the save dialogues of graphical user interfaces.The
print_figure()method now works in the following way:Most code parts I modified came from @mdboom and @leejjoon, so I humbly ask you for your opinions.