<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">When plotting a heatmap using <code class="notranslate">pyplot.imshow()</code>, then exporting the image to svg using <code class="notranslate">savefig</code>, the heatmap is exported as base64-encoded embedded png in the svg file. Although this behaviour is reasonable for an actual image being shown using <code class="notranslate">imshow</code>, it breaks up image scalability (which is often the point for vector graphics) when plotting a heatmap.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from matplotlib import pyplot as plt
import numpy as np
import random

BOUND = 100

data = np.zeros((BOUND, BOUND))

for _ in range(BOUND * 1000):
    x = random.randint(0, BOUND - 1)
    y = random.randint(0, BOUND - 1)
    data[x, y] += 1

plt.imshow(data, extent=(0, 5, 0, 5), cmap=&quot;Blues&quot;, origin=&quot;lower&quot;)
plt.savefig(&quot;test.svg&quot;, format=&quot;svg&quot;, bbox_inches=&quot;tight&quot;)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">random</span>

<span class="pl-v">BOUND</span> <span class="pl-c1">=</span> <span class="pl-c1">100</span>

<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">zeros</span>((<span class="pl-v">BOUND</span>, <span class="pl-v">BOUND</span>))

<span class="pl-k">for</span> <span class="pl-s1">_</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-v">BOUND</span> <span class="pl-c1">*</span> <span class="pl-c1">1000</span>):
    <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">random</span>.<span class="pl-en">randint</span>(<span class="pl-c1">0</span>, <span class="pl-v">BOUND</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span>)
    <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">random</span>.<span class="pl-en">randint</span>(<span class="pl-c1">0</span>, <span class="pl-v">BOUND</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span>)
    <span class="pl-s1">data</span>[<span class="pl-s1">x</span>, <span class="pl-s1">y</span>] <span class="pl-c1">+=</span> <span class="pl-c1">1</span>

<span class="pl-s1">plt</span>.<span class="pl-en">imshow</span>(<span class="pl-s1">data</span>, <span class="pl-s1">extent</span><span class="pl-c1">=</span>(<span class="pl-c1">0</span>, <span class="pl-c1">5</span>, <span class="pl-c1">0</span>, <span class="pl-c1">5</span>), <span class="pl-s1">cmap</span><span class="pl-c1">=</span><span class="pl-s">"Blues"</span>, <span class="pl-s1">origin</span><span class="pl-c1">=</span><span class="pl-s">"lower"</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">"test.svg"</span>, <span class="pl-s1">format</span><span class="pl-c1">=</span><span class="pl-s">"svg"</span>, <span class="pl-s1">bbox_inches</span><span class="pl-c1">=</span><span class="pl-s">"tight"</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto">The SVG file contains embedded png; this can be checked with any text editor. Also note that opening this file, then zooming on the squares' boundaries on the heatmap results in a blur; while the axes are not blurred by zooming (being vector images).</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">The heatmap part of the svg is actually an "array" or vector squares, without borders, of the desired colour; thus, it is possible to scale it to any extent without blurring.</p>
<p dir="auto"><strong>Alternatives</strong></p>
<p dir="auto">Exporting the same heatmap to <code class="notranslate">pdf</code> instead of <code class="notranslate">svg</code> leads to a weird, seemingly vector graphic (zoomable without blur) result where each square of the heatmap has a grey border. Somehow, this is not the case with any PDF viewer; for instance, <code class="notranslate">zathura</code> seems to render the pdf image fine. However, such a pdf included in a LaTeX document compiled with <code class="notranslate">xelatex</code> with a regular <code class="notranslate">\includegraphics</code> yields those weird borders.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>
<ul dir="auto">
<li>Operating system: ArchLinux <code class="notranslate">Linux 5.11.13-arch1-1 #1 SMP PREEMPT Sat, 10 Apr 2021 20:47:14 +0000 x86_64 GNU/Linux</code></li>
<li>Matplotlib version (<code class="notranslate">import matplotlib; print(matplotlib.__version__)</code>): 3.4.1</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): GTK3Agg</li>
<li>Python version: 3.9.3</li>
<li>Jupyter version (if applicable): N/A</li>
<li>Other libraries: N/A</li>
</ul>
<p dir="auto">Tested with matplotlib installed both from ArchLinux repositories and pip.</p>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">Currently, an image using the (default) setting of <code class="notranslate">interpolation="none"</code> 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. <a href="http://tavmjong.free.fr/SVG/IMAGE_RENDERING/index.html" rel="nofollow">http://tavmjong.free.fr/SVG/IMAGE_RENDERING/index.html</a>).</p>
<p dir="auto">In order to disable interpolation by the renderer, it is necessary to use the image-rendering CSS property, see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering</a> (specifically, we want to use the "pixelated" value).</p>
<p dir="auto">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 (<a href="https://caniuse.com/#search=image-rendering" rel="nofollow">https://caniuse.com/#search=image-rendering</a>).  (Inkscape supports "pixelated" since 0.92.2 (<a href="https://git.launchpad.net/inkscape/commit/?id=c3a191e4275ade05cf4bb4aab045ee22d050e703" rel="nofollow">https://git.launchpad.net/inkscape/commit/?id=c3a191e4275ade05cf4bb4aab045ee22d050e703</a>) 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 <a href="https://css-tricks.com/almanac/properties/i/image-rendering/" rel="nofollow">https://css-tricks.com/almanac/properties/i/image-rendering/</a></p>

<p dir="auto"><strong>Code for reproduction</strong></p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from pylab import *
plt.imshow([[1, 2], [3, 4]])
plt.savefig(&quot;/tmp/test.svg&quot;)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">pylab</span> <span class="pl-k">import</span> <span class="pl-c1">*</span>
<span class="pl-s1">plt</span>.<span class="pl-en">imshow</span>([[<span class="pl-c1">1</span>, <span class="pl-c1">2</span>], [<span class="pl-c1">3</span>, <span class="pl-c1">4</span>]])
<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">"/tmp/test.svg"</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>

<p dir="auto">Inkscape/Chromium/Firefox render the SVG as interpolated.</p>
<p dir="auto"><strong>Expected outcome</strong></p>


<p dir="auto">No interpolation.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: linux</li>
<li>Matplotlib version: master</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): svg</li>
<li>Python version: 3.6</li>
<li>Jupyter version (if applicable):</li>
<li>Other libraries:</li>
</ul>