Skip to content

Commit 522fbe7

Browse files
committed
Better documentation for print_figure refactoring.
1 parent 8159c81 commit 522fbe7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/matplotlib/backend_bases.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,11 @@ def get_supported_filetypes_grouped(cls):
20182018
groupings[name].sort()
20192019
return groupings
20202020

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

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

20942098
# get canvas object and print method for format
2095-
canvas = self._get_print_canvas(format)
2099+
canvas = self._get_output_canvas(format)
20962100
print_method = getattr(canvas, 'print_%s' % format)
20972101

20982102
if dpi is None:

lib/matplotlib/backends/backend_template.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@
3131
import matplotlib
3232
matplotlib.use('module://my_backend')
3333
34-
where my_backend.py is your module name. Thus syntax is also
34+
where my_backend.py is your module name. This syntax is also
3535
recognized in the rc file and in the -d argument in pylab, eg::
3636
3737
python simple_plot.py -dmodule://my_backend
3838
39+
If your backend implements support for saving figures (i.e. has a print_xyz()
40+
method) you can register it as the default handler for a given file type
41+
42+
from matplotlib.backend_bases import register_backend
43+
register_backend('xyz', 'my_backend', 'XYZ File Format')
44+
...
45+
plt.savefig("figure.xyz")
46+
3947
The files that are most relevant to backend_writers are
4048
4149
matplotlib/backends/backend_your_backend.py

0 commit comments

Comments
 (0)