<h3 dir="auto"><code class="notranslate">savefig</code> saves cropped images by default.</h3>
<h3 dir="auto"><strong>Bug summary</strong></h3>
<p dir="auto">It's probably an issue that almost everybody who uses matplotlib would have encountered. If you generate a figure - which often contains axis labels and legends - and save it with default settings, you'll get a cropped image.</p>
<p dir="auto">It's a duplicate of <a href="https://stackoverflow.com/q/61192115/3521099" rel="nofollow">my question on stackoverflow</a>.</p>
<h4 dir="auto"><strong>Code for reproduction</strong></h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
def plot():
    plt.figure(figsize=[3,3],linewidth=5,edgecolor='r') 
    ax=plt.subplot()
    ax.plot(range(10),range(10),label='label')
    ax.set_xlabel('xlabel\nxlabel\nxlabel')
    ax.set_ylabel('ylabel\nylabel\nylabel')
    ax.legend(bbox_to_anchor=[1,1])
plot()    
plt.savefig('no_tight_layout.png')"><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">def</span> <span class="pl-en">plot</span>():
    <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(<span class="pl-s1">figsize</span><span class="pl-c1">=</span>[<span class="pl-c1">3</span>,<span class="pl-c1">3</span>],<span class="pl-s1">linewidth</span><span class="pl-c1">=</span><span class="pl-c1">5</span>,<span class="pl-s1">edgecolor</span><span class="pl-c1">=</span><span class="pl-s">'r'</span>) 
    <span class="pl-s1">ax</span><span class="pl-c1">=</span><span class="pl-s1">plt</span>.<span class="pl-en">subplot</span>()
    <span class="pl-s1">ax</span>.<span class="pl-en">plot</span>(<span class="pl-en">range</span>(<span class="pl-c1">10</span>),<span class="pl-en">range</span>(<span class="pl-c1">10</span>),<span class="pl-s1">label</span><span class="pl-c1">=</span><span class="pl-s">'label'</span>)
    <span class="pl-s1">ax</span>.<span class="pl-en">set_xlabel</span>(<span class="pl-s">'xlabel<span class="pl-cce">\n</span>xlabel<span class="pl-cce">\n</span>xlabel'</span>)
    <span class="pl-s1">ax</span>.<span class="pl-en">set_ylabel</span>(<span class="pl-s">'ylabel<span class="pl-cce">\n</span>ylabel<span class="pl-cce">\n</span>ylabel'</span>)
    <span class="pl-s1">ax</span>.<span class="pl-en">legend</span>(<span class="pl-s1">bbox_to_anchor</span><span class="pl-c1">=</span>[<span class="pl-c1">1</span>,<span class="pl-c1">1</span>])
<span class="pl-en">plot</span>()    
<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'no_tight_layout.png'</span>)</pre></div>
<h4 dir="auto"><strong>Actual outcome</strong></h4>
<p dir="auto"><a href="https://i.stack.imgur.com/PcZgn.png" rel="nofollow"><img src="https://camo.githubusercontent.com/6255553d8a7b317d251abaf2ee0aba3bda398b2c7b5700a41e65bdfce21a990c/68747470733a2f2f692e737461636b2e696d6775722e636f6d2f50635a676e2e706e67" alt="no_tight_layout.png" data-canonical-src="https://i.stack.imgur.com/PcZgn.png" style="max-width: 100%;"></a></p>

<h3 dir="auto"><strong>Expected outcome</strong></h3>
<p dir="auto">If I generate the same plot in a jupyter notebook, without using <code class="notranslate">tight_layout</code> option, I see that all the elements of the plot are contained within the figure boundaries (shown in red).</p>
<p dir="auto"><a href="https://i.stack.imgur.com/TJh4r.png" rel="nofollow"><img src="https://camo.githubusercontent.com/97dd4a102df9934d1ac0643ada4079c80cf3a2a6d2fe2a681df473fb9ce27a01/68747470733a2f2f692e737461636b2e696d6775722e636f6d2f544a6834722e706e67" alt="jupyter notebook" data-canonical-src="https://i.stack.imgur.com/TJh4r.png" style="max-width: 100%;"></a></p>
<p dir="auto">This figure is generated in the output cell of a jupyter notebook(!).<br>
Then why it is not saved as it is? Why the saved image is by default different from the image jupyter notebook?<br>
In my opinion this is a very fundamental issue with matplotlib.<br>
Would't it make the lives of the users easier, if by default, all the elements are contained in the saved figure without the need of any workarounds?</p>
<h3 dir="auto"><strong>(Thanks to stackoverflow), we know few workarounds but each has a caveat of its own</strong>..</h3>
<p dir="auto"><strong>Workaround <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="611170" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/1" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/1/hovercard" href="https://github.com/matplotlib/matplotlib/pull/1">#1</a>:</strong> from within matplotlib: use of <strong><code class="notranslate">tight_layout</code></strong> option.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="plot()    
plt.savefig('tight_layout.png',bbox_inches='tight')"><pre class="notranslate"><code class="notranslate">plot()    
plt.savefig('tight_layout.png',bbox_inches='tight')
</code></pre></div>
<p dir="auto"><a href="https://i.stack.imgur.com/HQl7S.png" rel="nofollow"><img src="https://camo.githubusercontent.com/62053ded4f9b3fbf82a63cfe4ac37efd34b13b93735d1c96822e1aad0ec4c78d/68747470733a2f2f692e737461636b2e696d6775722e636f6d2f48516c37532e706e67" alt="tight_layout.png" data-canonical-src="https://i.stack.imgur.com/HQl7S.png" style="max-width: 100%;"></a></p>
<p dir="auto">It works for simple figures.<br>
<strong>However</strong>, in my experience, it is not reliable option in the case of more complex, multi-panel figures.<br>
<code class="notranslate">tight_layout</code> often fails with errors such as these:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
UserWarning: tight_layout not applied: number of rows in subplot specifications must be multiples of one another."><pre class="notranslate"><code class="notranslate">UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
UserWarning: tight_layout not applied: number of rows in subplot specifications must be multiples of one another.
</code></pre></div>
<p dir="auto"><strong>Workaround <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="611662" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/2" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/2/hovercard" href="https://github.com/matplotlib/matplotlib/pull/2">#2</a>:</strong> from outside of matplotlib: save the image in SVG format and then convert to png. For example using <code class="notranslate">--export-area-drawing</code> option in the <strong>inkscape</strong> command line UI or "resize to page" option in the inkscape's GUI.</p>
<p dir="auto"><strong>However</strong>, in this case you have to depend on external softwares which are difficult to add as dependencies in python packages (currently conda only hosts Windows version of inkscape).</p>
<h3 dir="auto"><strong>So my question is..</strong></h3>
<p dir="auto">Why doesn't matplotlib save the whole figure by default?</p>
<hr>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: Ubuntu 18.04</li>
<li>Matplotlib version: 3.1.2 (this is issue reproducible in previous version too.)</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>):</li>
<li>Python version: 3.6.5</li>
<li>Jupyter version (if applicable): 1.0</li>
<li>Other libraries:</li>
</ul>
<p dir="auto">Some ideas:</p>
<ul dir="auto">
<li>Drop the duplicate "nothing" entries in the marker style combo box (at least present in 1.5.0rc3).</li>
<li>Sort the entries alphabetically.</li>
<li>Add an icon with a representation of the marker/line style.</li>
</ul>