-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Refactor mechanism for saving files. #2588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
@@ -2057,29 +2018,23 @@ def get_supported_filetypes_grouped(cls): | |||
groupings[name].sort() | |||
return groupings | |||
|
|||
def _get_print_method(self, format): | |||
def _get_print_canvas(self, format): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_inches
support for backend_pgf (issue #2586). However, I can't do this properly sincetight_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 inFigureCanvasBase.print_figure()
.This required some major changes. I'll break them down to the following steps:
FigureCanvasBase
and thus a lot of code duplication. Movedprint_jpeg
andprint_tiff
to the Agg backend where they are actually implemented.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 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.