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

Simplify implementation of svg.image_inline. #14454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 10 doc/api/next_api_changes/2019-06-10-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RendererSVG now uses a single counter for externally written images
```````````````````````````````````````````````````````````````````

When using `RendererSVG` with ``rcParams["svg.image_inline"] ==
True``, externally written images now use a single counter even if the
``renderer.basename`` attribute is overwritten, rather than a counter per
basename.
QuLogic marked this conversation as resolved.
Show resolved Hide resolved

This change will only affect you if you used ``rcParams["svg.image_inline"] = True``
(the default is False) *and* manually modified ``renderer.basename``.
17 changes: 8 additions & 9 deletions 17 lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gzip
import hashlib
import io
import itertools
import logging
import re
import uuid
Expand Down Expand Up @@ -278,14 +279,11 @@ def __init__(self, width, height, svgwriter, basename=None, image_dpi=72):
self.image_dpi = image_dpi # actual dpi at which we rasterize stuff

self._groupd = {}
if not rcParams['svg.image_inline']:
assert basename is not None
self.basename = basename
self._imaged = {}
self.basename = basename
self._image_counter = itertools.count()
self._clipd = OrderedDict()
self._markers = {}
self._path_collection_id = 0
self._imaged = {}
self._hatchd = OrderedDict()
self._has_gouraud = False
self._n_gradients = 0
Expand Down Expand Up @@ -830,10 +828,11 @@ def draw_image(self, gc, x, y, im, transform=None):
"data:image/png;base64,\n" +
base64.b64encode(bytesio.getvalue()).decode('ascii'))
else:
self._imaged[self.basename] = (
self._imaged.get(self.basename, 0) + 1)
filename = '%s.image%d.png' % (
self.basename, self._imaged[self.basename])
if self.basename is None:
raise ValueError("Cannot save image data to filesystem when "
"writing SVG to an in-memory buffer")
filename = '{}.image{}.png'.format(
self.basename, next(self._image_counter))
_log.info('Writing image file for inclusion: %s', filename)
_png.write_png(im, filename)
oid = oid or 'Im_' + self._make_id('image', filename)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.