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

Commit522fbe7

Browse files
committed
Better documentation for print_figure refactoring.
1 parent8159c81 commit522fbe7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

‎lib/matplotlib/backend_bases.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,11 @@ def get_supported_filetypes_grouped(cls):
20182018
groupings[name].sort()
20192019
returngroupings
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
ifdpiisNone:

‎lib/matplotlib/backends/backend_template.py

Lines changed: 9 additions & 1 deletion
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)

[8]ページ先頭

©2009-2025 Movatter.jp