Skip to content

Write SVG uninterpolated images with image-rendering: pixelated. #10112

Closed

Description

@anntzer

Bug report

Bug summary

Currently, an image using the (default) setting of interpolation="none" will be written "as-it" by the SVG file; SVG renderers will then render them with interpolation (this is actually recommended by the SVG spec, see e.g. http://tavmjong.free.fr/SVG/IMAGE_RENDERING/index.html).

In order to disable interpolation by the renderer, it is necessary to use the image-rendering CSS property, see https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering (specifically, we want to use the "pixelated" value).

Support for this property is fairly incomplete; however it is at least available under a renderer-specific name for all of inkscape, chromium, firefox, and IE (https://caniuse.com/#search=image-rendering). (Inkscape supports "pixelated" since 0.92.2 (https://git.launchpad.net/inkscape/commit/?id=c3a191e4275ade05cf4bb4aab045ee22d050e703) but has supported "-inkscape-pixelated" for a while already.) It appears possible to just specify a bunch of different values to cover all cases, see e.g. comments in https://css-tricks.com/almanac/properties/i/image-rendering/

Code for reproduction

from pylab import *
plt.imshow([[1, 2], [3, 4]])
plt.savefig("/tmp/test.svg")

Actual outcome

Inkscape/Chromium/Firefox render the SVG as interpolated.

Expected outcome

No interpolation.

Matplotlib version

  • Operating system: linux
  • Matplotlib version: master
  • Matplotlib backend (print(matplotlib.get_backend())): svg
  • Python version: 3.6
  • Jupyter version (if applicable):
  • Other libraries:

Activity

  1. added a commit that references this issue on Apr 7, 2020
  2. github-actions commented on Apr 28, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  3. added this to the v3.3.0 milestone on Apr 28, 2023
  4. ksunden commented on Apr 28, 2023

    @ksunden
    Member

    Appears fixed by #17062

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions