8000 Refactor mechanism for saving files. by pwuertz · Pull Request #2588 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 2 commits into from
Nov 27, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Better documentation for print_figure refactoring.
  • Loading branch information
pwuertz committed Nov 26, 2013
commit 522fbe78c75e01b5ec34613efd81cd638a8a235d
8 changes: 6 additions & 2 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,11 @@ def get_supported_filetypes_grouped(cls):
groupings[name].sort()
return groupings

def _get_print_canvas(self, format):
def _get_output_canvas(self, format):
"""Return a canvas that is suitable for saving figures to a specified
file format. If necessary, this function will switch to a registered
backend that supports the format.
"""
method_name = 'print_%s' % format

# check if this canvas supports the requested format
Expand Down Expand Up @@ -2092,7 +2096,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
format = format.lower()

# get canvas object and print method for format
canvas = self._get_print_canvas(format)
canvas = self._get_output_canvas(format)
print_method = getattr(canvas, 'print_%s' % format)

if dpi is None:
Expand Down
10 changes: 9 additions & 1 deletion lib/matplotlib/backends/backend_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@
import matplotlib
matplotlib.use('module://my_backend')

where my_backend.py is your module name. Thus syntax is also
where my_backend.py is your module name. This syntax is also
recognized in the rc file and in the -d argument in pylab, eg::

python simple_plot.py -dmodule://my_backend

If your backend implements support for saving figures (i.e. has a print_xyz()
method) you can register it as the default handler for a given file type

from matplotlib.backend_bases import register_backend
register_backend('xyz', 'my_backend', 'XYZ File Format')
...
plt.savefig("figure.xyz")

The files that are most relevant to backend_writers are

matplotlib/backends/backend_your_backend.py
Expand Down
0