<h3 dir="auto">Bug report</h3>
<p dir="auto">matplotlib.pyplot picture is corrupted when the picture is too wide</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<p dir="auto">A minimum working example is here:</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

num_points = 1000
op_norms = range(1, num_points + 1)
op_names = [&quot;name {}&quot;.format(p) for p in op_norms]
    
for figwidth in [300, 400]:
    f = plt.figure(num=None, figsize=(figwidth, 6), facecolor='w', edgecolor='k')
    for i, op_norm in enumerate(op_norms):
        plt.semilogy(i, op_norm, &quot;o&quot;)

    plt.xticks(np.arange(num_points), op_names, rotation=90)
    plt.tight_layout()
    plt.grid(True)
    plt.savefig(&quot;wideplot_width_{}.png&quot;.format(figwidth), bbox_inches='tight')
    plt.close()```"><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-s1">num_points</span> <span class="pl-c1">=</span> <span class="pl-c1">1000</span>
<span class="pl-s1">op_norms</span> <span class="pl-c1">=</span> <span class="pl-en">range</span>(<span class="pl-c1">1</span>, <span class="pl-s1">num_points</span> <span class="pl-c1">+</span> <span class="pl-c1">1</span>)
<span class="pl-s1">op_names</span> <span class="pl-c1">=</span> [<span class="pl-s">"name {}"</span>.<span class="pl-en">format</span>(<span class="pl-s1">p</span>) <span class="pl-k">for</span> <span class="pl-s1">p</span> <span class="pl-c1">in</span> <span class="pl-s1">op_norms</span>]
    
<span class="pl-k">for</span> <span class="pl-s1">figwidth</span> <span class="pl-c1">in</span> [<span class="pl-c1">300</span>, <span class="pl-c1">400</span>]:
    <span class="pl-s1">f</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(<span class="pl-s1">num</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">figsize</span><span class="pl-c1">=</span>(<span class="pl-s1">figwidth</span>, <span class="pl-c1">6</span>), <span class="pl-s1">facecolor</span><span class="pl-c1">=</span><span class="pl-s">'w'</span>, <span class="pl-s1">edgecolor</span><span class="pl-c1">=</span><span class="pl-s">'k'</span>)
    <span class="pl-k">for</span> <span class="pl-s1">i</span>, <span class="pl-s1">op_norm</span> <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>(<span class="pl-s1">op_norms</span>):
        <span class="pl-s1">plt</span>.<span class="pl-en">semilogy</span>(<span class="pl-s1">i</span>, <span class="pl-s1">op_norm</span>, <span class="pl-s">"o"</span>)

    <span class="pl-s1">plt</span>.<span class="pl-en">xticks</span>(<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-s1">num_points</span>), <span class="pl-s1">op_names</span>, <span class="pl-s1">rotation</span><span class="pl-c1">=</span><span class="pl-c1">90</span>)
    <span class="pl-s1">plt</span>.<span class="pl-en">tight_layout</span>()
    <span class="pl-s1">plt</span>.<span class="pl-en">grid</span>(<span class="pl-c1">True</span>)
    <span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">"wideplot_width_{}.png"</span>.<span class="pl-en">format</span>(<span class="pl-s1">figwidth</span>), <span class="pl-s1">bbox_inches</span><span class="pl-c1">=</span><span class="pl-s">'tight'</span>)
    <span class="pl-s1">plt</span>.<span class="pl-en">close</span>()`<span class="pl-s">``</span></pre></div>
<p dir="auto"><strong>Expected outcome</strong>:<br>
When <code class="notranslate">figwidth=300</code>, everything is fine; see <a href="https://i.stack.imgur.com/DTeTE.png" rel="nofollow">here</a>. However, when it is increased to <code class="notranslate">figwidth=400</code>, the plot is corrupted (boarder is not complete, x axis label not complete, dirty ink etc.); see <a href="https://i.stack.imgur.com/1cMCl.png" rel="nofollow">here</a>.</p>
<ul dir="auto">
<li>Operating system: Debian GNU/Linux 10 (buster)</li>
<li>Matplotlib version (<code class="notranslate">import matplotlib; print(matplotlib.__version__)</code>): 3.3.2</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): agg</li>
<li>Python version: 3.7.9</li>
</ul>
<p dir="auto">matplotlib is installed from conda.</p>
<p dir="auto">Any hint would be very much appreciated! Thanks!</p>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">If I try to save a figure with 1024**3 pixels or more, the Python interpreter crashes.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<p dir="auto">The following script segfaults for me on two separate machines:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#! /usr/bin/env python

import matplotlib
import sys

matplotlib.use('agg')

import matplotlib.pyplot as plt

if len(sys.argv) == 3:
    figsize = (int(sys.argv[1]), int(sys.argv[2]))
else:
    print('using default figsize')
    figsize = (463, 232)

fig, ax = plt.subplots(figsize=figsize, dpi=100)
fig.savefig('big.png')"><pre class="notranslate"><span class="pl-c">#! /usr/bin/env python</span>

<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>
<span class="pl-k">import</span> <span class="pl-s1">sys</span>

<span class="pl-s1">matplotlib</span>.<span class="pl-en">use</span>(<span class="pl-s">'agg'</span>)

<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">if</span> <span class="pl-en">len</span>(<span class="pl-s1">sys</span>.<span class="pl-s1">argv</span>) <span class="pl-c1">==</span> <span class="pl-c1">3</span>:
    <span class="pl-s1">figsize</span> <span class="pl-c1">=</span> (<span class="pl-en">int</span>(<span class="pl-s1">sys</span>.<span class="pl-s1">argv</span>[<span class="pl-c1">1</span>]), <span class="pl-en">int</span>(<span class="pl-s1">sys</span>.<span class="pl-s1">argv</span>[<span class="pl-c1">2</span>]))
<span class="pl-k">else</span>:
    <span class="pl-en">print</span>(<span class="pl-s">'using default figsize'</span>)
    <span class="pl-s1">figsize</span> <span class="pl-c1">=</span> (<span class="pl-c1">463</span>, <span class="pl-c1">232</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-s1">figsize</span>, <span class="pl-s1">dpi</span><span class="pl-c1">=</span><span class="pl-c1">100</span>)
<span class="pl-s1">fig</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'big.png'</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto">This segfaults when trying to create this image. The image size is 46300 × 23200 = 1,074,160,000. For comparison, 1024**3 is 1,073,741,824.</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">No segfault. If I run the script with arguments <code class="notranslate">462 232</code> to create an image of 1,071,840,000 pixels, I get no crash.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>
<ul dir="auto">
<li>Operating system: Centos 7.8 or Fedora 33</li>
<li>Matplotlib version: 3.3.3</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): agg</li>
<li>Python version: 3.8.6</li>
</ul>
<p dir="auto">Matplotlib installed through Conda using conda-forge.</p>
<p dir="auto"><strong>Other information</strong></p>
<p dir="auto">The relevant stacktrace is short:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#0  0x00007fffd699ffbd in agg::renderer_base&lt;agg::pixfmt_alpha_blend_rgba&lt;fixed_blender_rgba_plain&lt;agg::rgba8T&lt;agg::linear&gt;, agg::order_rgba&gt;, agg::row_accessor&lt;unsigned char&gt; &gt; &gt;::clear(agg::rgba8T&lt;agg::linear&gt; const&amp;) [clone .part.61] [clone .lto_priv.101] ()
   from /a/lib/python3.8/site-packages/matplotlib/backends/_backend_agg.cpython-38-x86_64-linux-gnu.so
#1  0x00007fffd6994d8d in PyRendererAgg_init(PyRendererAgg*, _object*, _object*) [clone .lto_priv.107] ()
   from /a/lib/python3.8/site-packages/matplotlib/backends/_backend_agg.cpython-38-x86_64-linux-gnu.so
#2  0x0000555555683888 in type_call (kwds=0x0, args=0x7fffe773fe40, type=&lt;optimized out&gt;)
    at /home/conda/feedstock_root/build_artifacts/python-split_1602094424782/work/Objects/typeobject.c:994"><pre class="notranslate"><code class="notranslate">#0  0x00007fffd699ffbd in agg::renderer_base&lt;agg::pixfmt_alpha_blend_rgba&lt;fixed_blender_rgba_plain&lt;agg::rgba8T&lt;agg::linear&gt;, agg::order_rgba&gt;, agg::row_accessor&lt;unsigned char&gt; &gt; &gt;::clear(agg::rgba8T&lt;agg::linear&gt; const&amp;) [clone .part.61] [clone .lto_priv.101] ()
   from /a/lib/python3.8/site-packages/matplotlib/backends/_backend_agg.cpython-38-x86_64-linux-gnu.so
#1  0x00007fffd6994d8d in PyRendererAgg_init(PyRendererAgg*, _object*, _object*) [clone .lto_priv.107] ()
   from /a/lib/python3.8/site-packages/matplotlib/backends/_backend_agg.cpython-38-x86_64-linux-gnu.so
#2  0x0000555555683888 in type_call (kwds=0x0, args=0x7fffe773fe40, type=&lt;optimized out&gt;)
    at /home/conda/feedstock_root/build_artifacts/python-split_1602094424782/work/Objects/typeobject.c:994
</code></pre></div>
<p dir="auto">I am running this test on 64-bit machines and I can confirm that these are <em>not</em> simple out-of-memory errors.</p>