<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">Definitely a low-priority bug, but at some figure sizes, there seems to be an issue with the colorbar not being drawn at the correct position in some backends (seems like PDF and SVG are affected, but not Agg).</p>
<p dir="auto">The colorbar "fill" (the actual colored bit) will not line up with the box that contains it (the black marker edge that makes the rectangle that is filled by the color bar, see below). Seems like some sort of rounding issue.</p>
<p dir="auto">I have a more "dramatic" example, but still need to distill it to a minimum working example, as it is a plot of proprietary data.</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="import matplotlib.pyplot as plt
import matplotlib.cm

fig, ax = plt.subplots(figsize=(2, 1.5))

plt.plot()

sm = matplotlib.cm.ScalarMappable()
sm.set_array([])
plt.colorbar(sm)

plt.savefig('/home/bbeltr1/Downloads/test.svg')
plt.savefig('/home/bbeltr1/Downloads/test.pdf')
plt.savefig('/home/bbeltr1/Downloads/test.png', dpi=800)
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</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">matplotlib</span>.<span class="pl-s1">cm</span>

<span class="pl-s1">fig</span>, <span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>(<span class="pl-s1">figsize</span><span class="pl-c1">=</span>(<span class="pl-c1">2</span>, <span class="pl-c1">1.5</span>))

<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>()

<span class="pl-s1">sm</span> <span class="pl-c1">=</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">cm</span>.<span class="pl-v">ScalarMappable</span>()
<span class="pl-s1">sm</span>.<span class="pl-en">set_array</span>([])
<span class="pl-s1">plt</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">sm</span>)

<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'/home/bbeltr1/Downloads/test.svg'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'/home/bbeltr1/Downloads/test.pdf'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'/home/bbeltr1/Downloads/test.png'</span>, <span class="pl-s1">dpi</span><span class="pl-c1">=</span><span class="pl-c1">800</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>

<p dir="auto">SVG:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/1475390/79055002-608d3d00-7bfe-11ea-9487-fa3c80535bfd.png"><img src="https://user-images.githubusercontent.com/1475390/79055002-608d3d00-7bfe-11ea-9487-fa3c80535bfd.png" alt="test svg" style="max-width: 100%;"></a></p>
<p dir="auto">PDF:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/1475390/79055003-62570080-7bfe-11ea-8de0-c6afad7dc7ab.png"><img src="https://user-images.githubusercontent.com/1475390/79055003-62570080-7bfe-11ea-8de0-c6afad7dc7ab.png" alt="test pdf" style="max-width: 100%;"></a></p>
<p dir="auto">PNG:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/1475390/79055004-6420c400-7bfe-11ea-953f-6b3071b74244.png"><img src="https://user-images.githubusercontent.com/1475390/79055004-6420c400-7bfe-11ea-953f-6b3071b74244.png" alt="test" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">The PNG output has the expected outcome.</p>


<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: Debian Jessie</li>
<li>Matplotlib version: master</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>):</li>
<li>Python version: 3.7</li>
<li>Jupyter version (if applicable):</li>
<li>Other libraries:</li>
</ul>
<p dir="auto">The following example (with Matplotlib 2.0.0b3) causes the colorbar inside the colorbar axes to be offset when outputting to PDF with a low DPI:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
im = ax.imshow([[1]])
fig.colorbar(im)
fig.savefig('colorbar_test.pdf', dpi=7)"><pre class="notranslate"><code class="notranslate">import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
im = ax.imshow([[1]])
fig.colorbar(im)
fig.savefig('colorbar_test.pdf', dpi=7)
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/314716/17089570/05e193be-51f6-11e6-953a-408df28dd8e4.png"><img src="https://cloud.githubusercontent.com/assets/314716/17089570/05e193be-51f6-11e6-953a-408df28dd8e4.png" alt="colorbar_test" style="max-width: 100%;"></a></p>
<p dir="auto">This wasn't an issue with Matplotlib 1.4:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/314716/17089590/4598aa88-51f6-11e6-8186-9829c4118c95.png"><img src="https://cloud.githubusercontent.com/assets/314716/17089590/4598aa88-51f6-11e6-8186-9829c4118c95.png" alt="colorbar_test" style="max-width: 100%;"></a></p>
<p dir="auto">and the bug was apparently introduces in Matplotlib 1.5:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/314716/17089597/668bb4d8-51f6-11e6-8261-28e7becd97d6.png"><img src="https://cloud.githubusercontent.com/assets/314716/17089597/668bb4d8-51f6-11e6-8261-28e7becd97d6.png" alt="colorbar_test" style="max-width: 100%;"></a></p>