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

Appearance settings

Commit 7c224b5

Browse filesBrowse files
authored
Merge pull request #14454 from anntzer/svg.image_inline
Simplify implementation of svg.image_inline.
2 parents a2ff624 + 3c9e398 commit 7c224b5
Copy full SHA for 7c224b5

File tree

Expand file treeCollapse file tree

2 files changed

+18
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-9
lines changed
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
RendererSVG now uses a single counter for externally written images
2+
```````````````````````````````````````````````````````````````````
3+
4+
When using `RendererSVG` with ``rcParams["svg.image_inline"] ==
5+
True``, externally written images now use a single counter even if the
6+
``renderer.basename`` attribute is overwritten, rather than a counter per
7+
basename.
8+
9+
This change will only affect you if you used ``rcParams["svg.image_inline"] = True``
10+
(the default is False) *and* manually modified ``renderer.basename``.

‎lib/matplotlib/backends/backend_svg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_svg.py
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import gzip
44
import hashlib
55
import io
6+
import itertools
67
import logging
78
import re
89
import uuid
@@ -278,14 +279,11 @@ def __init__(self, width, height, svgwriter, basename=None, image_dpi=72):
278279
self.image_dpi = image_dpi # actual dpi at which we rasterize stuff
279280

280281
self._groupd = {}
281-
if not rcParams['svg.image_inline']:
282-
assert basename is not None
283-
self.basename = basename
284-
self._imaged = {}
282+
self.basename = basename
283+
self._image_counter = itertools.count()
285284
self._clipd = OrderedDict()
286285
self._markers = {}
287286
self._path_collection_id = 0
288-
self._imaged = {}
289287
self._hatchd = OrderedDict()
290288
self._has_gouraud = False
291289
self._n_gradients = 0
@@ -830,10 +828,11 @@ def draw_image(self, gc, x, y, im, transform=None):
830828
"data:image/png;base64,\n" +
831829
base64.b64encode(bytesio.getvalue()).decode('ascii'))
832830
else:
833-
self._imaged[self.basename] = (
834-
self._imaged.get(self.basename, 0) + 1)
835-
filename = '%s.image%d.png' % (
836-
self.basename, self._imaged[self.basename])
831+
if self.basename is None:
832+
raise ValueError("Cannot save image data to filesystem when "
833+
"writing SVG to an in-memory buffer")
834+
filename = '{}.image{}.png'.format(
835+
self.basename, next(self._image_counter))
837836
_log.info('Writing image file for inclusion: %s', filename)
838837
_png.write_png(im, filename)
839838
oid = oid or 'Im_' + self._make_id('image', filename)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.