<p dir="auto"><a href="https://sourceforge.net/tracker/?func=detail&amp;aid=3057301&amp;group_id=80706&amp;atid=560723" rel="nofollow">Original report at SourceForge, opened Wed Sep  1 04:54:13 2010</a></p>
<p dir="auto">instead of only:<br>
plt.figure(1)<br>
the following:<br>
plt.figure('today')<br>
would open a figure called 'today' instead of 'figure 1'</p>
<p dir="auto">Example usage: when opening a lot of tabbed figures (in Spyder) it would help if the tabs have meaningful names.</p>
<h3 dir="auto">SourceForge Comments</h3>
<h4 dir="auto">On Sun Sep  5 08:09:52 2010, None wrote:</h4>
<p dir="auto">+1<br>
good idea<br>
and not all that difficult to do.</p>
<p dir="auto">you just need to ensure that the identifier remains unique.</p>
<p dir="auto">I think the use of logging in matplotlib is not right.</p>
<p dir="auto">Unfortunately the official logging documentation is not quite comprehensive. I'll try to explain in the following how I understand that logging should be used.</p>
<p dir="auto"><strong>TLDR: I propose to just remove <code class="notranslate">matplotlib._set_logger_verbose_level()</code> and all logging issues are gone. - Maybe add a bit of documentation how to use logging, but that's really not matplotlib specific.</strong></p>
<h2 dir="auto">How logging should be used in simple cases</h2>
<p dir="auto">In the minimal case, libraries do only define a logger and call the respective <code class="notranslate">info()</code>, <code class="notranslate">error()</code> etc. functions on that logger.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="_log = logging.getLogger(__name__)"><pre class="notranslate"><code class="notranslate">_log = logging.getLogger(__name__)
</code></pre></div>
<p dir="auto">In this case, the library does not care about handling at all. IMO this is generally good practice as the library will issue messages, but it will not care which will be delivered or where they will go to (stdout, file, ...). That's the task of the code using the library:</p>
<ul dir="auto">
<li>
<p dir="auto">if the programmer does not care about logging at all, <a href="https://docs.python.org/3/library/logging.html#logging.lastResort" rel="nofollow">logging.lastResort</a> is used, which is a StreamHandler to stderr. This makes sure the messages go somewhere even without configuration (note: this was introduced in 3.2).</p>
</li>
<li>
<p dir="auto">if the programmer wants to control the logging, the simple way is <a href="https://docs.python.org/3/library/logging.html#logging.basicConfig" rel="nofollow">logging.basicConfig()</a>. This is sufficent to redirect output to files, set the global log level etc.</p>
</li>
</ul>
<h2 dir="auto">How matplotlib uses logging</h2>
<h3 dir="auto">Former times</h3>
<p dir="auto">There has been some argument parsing magic, so that passing <code class="notranslate">--verbose</code> to a script using matplotlib could be used to control matplotlib's logging. This has been removed because it's too magical and can badly interfere with the argument handling of a script.</p>
<h3 dir="auto">Now</h3>
<p dir="auto">Currently, there is only <code class="notranslate">matplotlib._set_logger_verbose_level()</code>.</p>
<p dir="auto">If unused (default) the processes work as described above for loggging in simple cases.</p>
<p dir="auto">The function binds a new StreamHandler (named <em>console</em> in the code) to <code class="notranslate">_log</code> and controls the level of the handler. This works ok for the case when the matplotlib-using programmer does not configure any logging himself: The messages are sent to <em>console</em>. <code class="notranslate">logging.lastResort</code> is not used. However, if logging <code class="notranslate">basicConfig()</code> is used, we have two handlers: <em>console</em> plus the one from the config, as can be seen when running</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import matplotlib
import logging
logging.basicConfig()
matplotlib._set_logger_verbose_level('helpful')
matplotlib._log.info('test')"><pre class="notranslate"><code class="notranslate">import matplotlib
import logging
logging.basicConfig()
matplotlib._set_logger_verbose_level('helpful')
matplotlib._log.info('test')
</code></pre></div>
<p dir="auto">This outputs the message twice</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="test
INFO:matplotlib:test"><pre class="notranslate"><code class="notranslate">test
INFO:matplotlib:test
</code></pre></div>
<p dir="auto">luckily <code class="notranslate">_set_logger_verbose_level()</code> is private and should not be used currently.</p>
<h3 dir="auto">Future</h3>
<p dir="auto">The proposal in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="396656501" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/13129" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/13129/hovercard" href="https://github.com/matplotlib/matplotlib/pull/13129">#13129</a> is making <code class="notranslate">_set_logger_verbose_level()</code> indirectly public through some convenience functions. <em>IMHO this is the wrong way to go as described above</em>.</p>
<p dir="auto">What we should do is just remove <code class="notranslate">_set_logger_verbose_level()</code>. It's standard use casescan be handled using <code class="notranslate">logging.basicConfig()</code>. e.g.</p>
<ul dir="auto">
<li>redirecting to file: `logging.basicConfig(filename='errors.log')</li>
<li>setting the level: `logging.basicConfig(level='debug')</li>
</ul>
<p dir="auto"><code class="notranslate">logging.basicConfig()</code> is actually more general, e.g.</p>
<ul dir="auto">
<li>specifying the output format</li>
<li>choosing between append and overwrite for a file.</li>
<li>using another handler</li>
<li>etc.</li>
</ul>
<p dir="auto">There's one special case that we do not cover: Logging matplotlibs output somewhere else that other logging output. That was possible / the case for <code class="notranslate">_set_logger_verbose_level()</code>. Not sure if it was by design or just accidentially. If a user really needs that, he has to attach a handler to the matplotlib logger (but also maybe set <code class="notranslate">_log.propagate = False</code>. We could add a convenience function for this, but IMHO this is rather an advance usage and it should be sufficient to make the matplotlib logger accessible.</p>