Parameters ---------- filename : str or path-like or file-like Output target; if a string, a file will be opened for writing. metadata : dict[str, Any], optional Metadata in the SVG file defined as key-value pairs of strings, date
(self, filename, *, bbox_inches_restore=None, metadata=None)
| 1321 | fixed_dpi = 72 |
| 1322 | |
| 1323 | def print_svg(self, filename, *, bbox_inches_restore=None, metadata=None): |
| 1324 | """ |
| 1325 | Parameters |
| 1326 | ---------- |
| 1327 | filename : str or path-like or file-like |
| 1328 | Output target; if a string, a file will be opened for writing. |
| 1329 | |
| 1330 | metadata : dict[str, Any], optional |
| 1331 | Metadata in the SVG file defined as key-value pairs of strings, |
| 1332 | datetimes, or lists of strings, e.g., ``{'Creator': 'My software', |
| 1333 | 'Contributor': ['Me', 'My Friend'], 'Title': 'Awesome'}``. |
| 1334 | |
| 1335 | The standard keys and their value types are: |
| 1336 | |
| 1337 | * *str*: ``'Coverage'``, ``'Description'``, ``'Format'``, |
| 1338 | ``'Identifier'``, ``'Language'``, ``'Relation'``, ``'Source'``, |
| 1339 | ``'Title'``, and ``'Type'``. |
| 1340 | * *str* or *list of str*: ``'Contributor'``, ``'Creator'``, |
| 1341 | ``'Keywords'``, ``'Publisher'``, and ``'Rights'``. |
| 1342 | * *str*, *date*, *datetime*, or *tuple* of same: ``'Date'``. If a |
| 1343 | non-*str*, then it will be formatted as ISO 8601. |
| 1344 | |
| 1345 | Values have been predefined for ``'Creator'``, ``'Date'``, |
| 1346 | ``'Format'``, and ``'Type'``. They can be removed by setting them |
| 1347 | to `None`. |
| 1348 | |
| 1349 | Information is encoded as `Dublin Core Metadata`__. |
| 1350 | |
| 1351 | .. _DC: https://www.dublincore.org/specifications/dublin-core/ |
| 1352 | |
| 1353 | __ DC_ |
| 1354 | """ |
| 1355 | with cbook.open_file_cm(filename, "w", encoding="utf-8") as fh: |
| 1356 | if not cbook.file_requires_unicode(fh): |
| 1357 | fh = codecs.getwriter('utf-8')(fh) |
| 1358 | dpi = self.figure.dpi |
| 1359 | self.figure.dpi = 72 |
| 1360 | width, height = self.figure.get_size_inches() |
| 1361 | w, h = width * 72, height * 72 |
| 1362 | renderer = MixedModeRenderer( |
| 1363 | self.figure, width, height, dpi, |
| 1364 | RendererSVG(w, h, fh, image_dpi=dpi, metadata=metadata), |
| 1365 | bbox_inches_restore=bbox_inches_restore) |
| 1366 | self.figure.draw(renderer) |
| 1367 | renderer.finalize() |
| 1368 | |
| 1369 | def print_svgz(self, filename, **kwargs): |
| 1370 | with (cbook.open_file_cm(filename, "wb") as fh, |
no test coverage detected