Save a `.Figure` to this file as a new page. Any other keyword arguments are passed to `~.Figure.savefig`. Parameters ---------- figure : `.Figure` or int, default: the active figure The figure, or index of the figure, that is saved to the file.
(self, figure=None, **kwargs)
| 980 | shutil.move(tex_source.with_suffix(".pdf"), self._output_name) |
| 981 | |
| 982 | def savefig(self, figure=None, **kwargs): |
| 983 | """ |
| 984 | Save a `.Figure` to this file as a new page. |
| 985 | |
| 986 | Any other keyword arguments are passed to `~.Figure.savefig`. |
| 987 | |
| 988 | Parameters |
| 989 | ---------- |
| 990 | figure : `.Figure` or int, default: the active figure |
| 991 | The figure, or index of the figure, that is saved to the file. |
| 992 | """ |
| 993 | if not isinstance(figure, Figure): |
| 994 | if figure is None: |
| 995 | manager = Gcf.get_active() |
| 996 | else: |
| 997 | manager = Gcf.get_fig_manager(figure) |
| 998 | if manager is None: |
| 999 | raise ValueError(f"No figure {figure}") |
| 1000 | figure = manager.canvas.figure |
| 1001 | |
| 1002 | width, height = figure.get_size_inches() |
| 1003 | if self._n_figures == 0: |
| 1004 | self._write_header(width, height) |
| 1005 | else: |
| 1006 | # \pdfpagewidth and \pdfpageheight exist on pdftex, xetex, and |
| 1007 | # luatex<0.85; they were renamed to \pagewidth and \pageheight |
| 1008 | # on luatex>=0.85. |
| 1009 | self._file.write( |
| 1010 | rb'\newpage' |
| 1011 | rb'\ifdefined\pdfpagewidth\pdfpagewidth\else\pagewidth\fi=%fin' |
| 1012 | rb'\ifdefined\pdfpageheight\pdfpageheight\else\pageheight\fi=%fin' |
| 1013 | b'%%\n' % (width, height) |
| 1014 | ) |
| 1015 | figure.savefig(self._file, format="pgf", backend="pgf", **kwargs) |
| 1016 | self._n_figures += 1 |
| 1017 | |
| 1018 | def get_pagecount(self): |
| 1019 | """Return the current number of pages in the multipage pdf file.""" |