Render the figure to a filesystem path or a file-like object. Parameters are as for `.print_figure`, except that *dsc_comments* is a string containing Document Structuring Convention comments, generated from the *metadata* parameter to `.print_figure`.
(
self, fmt, outfile, *,
dpi, dsc_comments, orientation, papertype,
bbox_inches_restore=None)
| 1013 | bbox_inches_restore=bbox_inches_restore, **kwargs) |
| 1014 | |
| 1015 | def _print_figure( |
| 1016 | self, fmt, outfile, *, |
| 1017 | dpi, dsc_comments, orientation, papertype, |
| 1018 | bbox_inches_restore=None): |
| 1019 | """ |
| 1020 | Render the figure to a filesystem path or a file-like object. |
| 1021 | |
| 1022 | Parameters are as for `.print_figure`, except that *dsc_comments* is a |
| 1023 | string containing Document Structuring Convention comments, |
| 1024 | generated from the *metadata* parameter to `.print_figure`. |
| 1025 | """ |
| 1026 | is_eps = fmt == 'eps' |
| 1027 | if not (isinstance(outfile, (str, os.PathLike)) |
| 1028 | or is_writable_file_like(outfile)): |
| 1029 | raise ValueError("outfile must be a path or a file-like object") |
| 1030 | |
| 1031 | # find the appropriate papertype |
| 1032 | width, height = self.figure.get_size_inches() |
| 1033 | if is_eps or papertype == 'figure': |
| 1034 | paper_width, paper_height = width, height |
| 1035 | else: |
| 1036 | paper_width, paper_height = orientation.swap_if_landscape( |
| 1037 | papersize[papertype]) |
| 1038 | |
| 1039 | # center the figure on the paper |
| 1040 | xo = 72 * 0.5 * (paper_width - width) |
| 1041 | yo = 72 * 0.5 * (paper_height - height) |
| 1042 | |
| 1043 | llx = xo |
| 1044 | lly = yo |
| 1045 | urx = llx + self.figure.bbox.width |
| 1046 | ury = lly + self.figure.bbox.height |
| 1047 | rotation = 0 |
| 1048 | if orientation is _Orientation.landscape: |
| 1049 | llx, lly, urx, ury = lly, llx, ury, urx |
| 1050 | xo, yo = 72 * paper_height - yo, xo |
| 1051 | rotation = 90 |
| 1052 | bbox = (llx, lly, urx, ury) |
| 1053 | |
| 1054 | self._pswriter = StringIO() |
| 1055 | |
| 1056 | # mixed mode rendering |
| 1057 | ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi) |
| 1058 | renderer = MixedModeRenderer( |
| 1059 | self.figure, width, height, dpi, ps_renderer, |
| 1060 | bbox_inches_restore=bbox_inches_restore) |
| 1061 | |
| 1062 | self.figure.draw(renderer) |
| 1063 | |
| 1064 | def print_figure_impl(fh): |
| 1065 | # write the PostScript headers |
| 1066 | if is_eps: |
| 1067 | print("%!PS-Adobe-3.0 EPSF-3.0", file=fh) |
| 1068 | else: |
| 1069 | print("%!PS-Adobe-3.0", file=fh) |
| 1070 | if papertype != 'figure': |
| 1071 | print(f"%%DocumentPaperSizes: {papertype}", file=fh) |
| 1072 | print("%%Pages: 1", file=fh) |
nothing calls this directly
no test coverage detected