Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mdboom merged 2 commits intomatplotlib:masterfrompwuertz:print_refactor
Nov 27, 2013
Merged

Refactor mechanism for saving files.#2588

mdboom merged 2 commits intomatplotlib:masterfrompwuertz:print_refactor
Nov 27, 2013

Conversation

pwuertz
Copy link
Contributor

I was trying to fixbbox_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:

  • Removed print_ methods fromFigureCanvasBase and thus a lot of code duplication. Movedprint_jpeg andprint_tiff to the Agg backend where they are actually implemented.
  • Picked up the rather dormant system for mapping file-types to backends inbackend_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().
  • Default format-to-backend mappings can be added or changed byregister_backend(). This is also reflected in the save dialogues of graphical user interfaces.

Theprint_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.

@mdboom
Copy link
Member

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 ofsubprocess).

@@ -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):
Copy link
Member

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. 😄

Copy link
ContributorAuthor

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 :)

@pelson
Copy link
Member

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

@pwuertz
Copy link
ContributorAuthor

@pelson, I didn't find any good place to document this newFigureCanvas alias other than putting it inbackend_template.py.
Also, I think this alias convention won't break anything at all. The alias is only required if you want deferred imports when saving to known/registered file formats - the behaviour of this wasn't configurable yet. But I must admit that I don't know any implementation details concerning IPython.

@pwuertz
Copy link
ContributorAuthor

@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.
@pwuertz
Copy link
ContributorAuthor

@pelson: I think I found a nice place for adding some documentation, an example is in thebackend_template.py docstring now. Also that canvas getter method is renamed and documented.

@pelson
Copy link
Member

I was thinking thebackend_bases.py file, but it may be the template is just as good.

@mdboom - I support this change, but it is sufficiently big that I'd like a second opinion.

👍

@mdboom
Copy link
Member

I agree, this really simplifies things. Merging.

mdboom added a commit that referenced this pull requestNov 27, 2013
Refactor mechanism for saving files.
@mdboommdboom merged commitbe24fc9 intomatplotlib:masterNov 27, 2013
@pwuertzpwuertz deleted the print_refactor branchNovember 27, 2013 14:04
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@pwuertz@mdboom@pelson

[8]ページ先頭

©2009-2025 Movatter.jp