Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
@anntzer

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:

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