<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">When storing plots as pdf, the colorbar is at the wrong position, off by a small amount:</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 numpy as np
import matplotlib

print(matplotlib.__version__)

rng = np.random.default_rng(0)
image = rng.normal(size=(40, 40))

# only happens at this exact figure size....
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(2.976338729763387, 1.4881693648816936), constrained_layout=True)
img1 = ax1.imshow(image)
img2 = ax2.imshow(image)
fig.colorbar(img1, orientation='horizontal', ax=ax1)
fig.colorbar(img2, orientation='horizontal', ax=ax2)
plt.savefig('colorbar.pdf')"><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">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>

<span class="pl-en">print</span>(<span class="pl-s1">matplotlib</span>.<span class="pl-s1">__version__</span>)

<span class="pl-s1">rng</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">default_rng</span>(<span class="pl-c1">0</span>)
<span class="pl-s1">image</span> <span class="pl-c1">=</span> <span class="pl-s1">rng</span>.<span class="pl-en">normal</span>(<span class="pl-s1">size</span><span class="pl-c1">=</span>(<span class="pl-c1">40</span>, <span class="pl-c1">40</span>))

<span class="pl-c"># only happens at this exact figure size....</span>
<span class="pl-s1">fig</span>, (<span class="pl-s1">ax1</span>, <span class="pl-s1">ax2</span>) <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>(<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-s1">figsize</span><span class="pl-c1">=</span>(<span class="pl-c1">2.976338729763387</span>, <span class="pl-c1">1.4881693648816936</span>), <span class="pl-s1">constrained_layout</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
<span class="pl-s1">img1</span> <span class="pl-c1">=</span> <span class="pl-s1">ax1</span>.<span class="pl-en">imshow</span>(<span class="pl-s1">image</span>)
<span class="pl-s1">img2</span> <span class="pl-c1">=</span> <span class="pl-s1">ax2</span>.<span class="pl-en">imshow</span>(<span class="pl-s1">image</span>)
<span class="pl-s1">fig</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">img1</span>, <span class="pl-s1">orientation</span><span class="pl-c1">=</span><span class="pl-s">'horizontal'</span>, <span class="pl-s1">ax</span><span class="pl-c1">=</span><span class="pl-s1">ax1</span>)
<span class="pl-s1">fig</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">img2</span>, <span class="pl-s1">orientation</span><span class="pl-c1">=</span><span class="pl-s">'horizontal'</span>, <span class="pl-s1">ax</span><span class="pl-c1">=</span><span class="pl-s1">ax2</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'colorbar.pdf'</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto">png converted from pdf output using <code class="notranslate">pdftoppm -r 600 -png -singlefile colorbar.pdf colorbar</code>:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/5488440/121939432-50667580-cd4d-11eb-8c95-cdb375c63842.png"><img src="https://user-images.githubusercontent.com/5488440/121939432-50667580-cd4d-11eb-8c95-cdb375c63842.png" alt="colorbar" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: Manjaro Linux</li>
<li>Matplotlib version (<code class="notranslate">import matplotlib; print(matplotlib.__version__)</code>): 3.4.2</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): pdf (since plot saved as pdf)</li>
<li>Python version: 3.9.5</li>
</ul>
<p dir="auto">Hi all,</p>
<p dir="auto">I could not find a similar issue so forgive me if its a duplicate. We are trying to get a couple of our tests suites to execute on mpl 1.x and 2.0 without having to duplicate the baseline images. The <code class="notranslate">classic</code> style helps a lot but there are still many small issues mainly related to text positioning. Is there a way I can force it to behave the same on mpl 1.x and 2.0?</p>
<p dir="auto">A simple example demonstrating the problem:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
plt.style.use(&quot;classic&quot;)
plt.plot([1, 2, 3, 4])
plt.savefig(&quot;out.png&quot;)"><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-s1">plt</span>.<span class="pl-s1">style</span>.<span class="pl-en">use</span>(<span class="pl-s">"classic"</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">plot</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">"out.png"</span>)</pre></div>
<p dir="auto">The difference is subtle but enough to cause issues when testing - the text baseline (or center line I guess) is different for both. This was run for mpl 1.5.3 and mpl 2.0.0.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/800487/22174693/c4a78ce6-dfe4-11e6-9a7b-ed516123f177.png"><img width="373" alt="screen shot 2017-01-21 at 14 19 41" src="https://cloud.githubusercontent.com/assets/800487/22174693/c4a78ce6-dfe4-11e6-9a7b-ed516123f177.png" style="max-width: 100%;"></a></p>