Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e575fc7

Browse files
committed
ENH: add a user-freindly verbose interface
ENH: set level to INFO and add pyplot.debug() DOC: add whats new and update FAQs DOC: fix wording ENH: change name to set_loglevel FIX: lower case
1 parent 2b86111 commit e575fc7

File tree

5 files changed

+76
-11
lines changed

5 files changed

+76
-11
lines changed

doc/devel/contributing.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ Then they will receive messages like::
448448
matplotlib.yourmodulename: 347 - INFO - Here is some information
449449
matplotlib.yourmodulename: 348 - DEBUG - Here is some more detailed information
450450

451+
More straight forward helper methods are available to end-users as well::
452+
453+
import matplotlib.pyplot as plt
454+
plt.set_loglevel(level='info') # or plt.set_loglevel(level='debug')
455+
451456
Which logging level to use?
452457
~~~~~~~~~~~~~~~~~~~~~~~~~~~
453458

doc/faq/troubleshooting_faq.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,16 @@ provide the following information in your e-mail to the `mailing list
120120

121121
python -c "from logging import *; basicConfig(level=DEBUG); from pylab import *; plot(); show()"
122122

123+
If you want to trigger logging in a script, it can be done with helper
124+
functions::
123125

124-
If you want to put the debugging hooks in your own code, then the
125-
most simple way to do so is to insert the following *before* any calls
126-
to ``import matplotlib``::
126+
import matplotlib.pyplot as plt
127+
plt.set_loglevel(level='info') # or plt.set_loglevel(level='debug')
128+
129+
130+
If you want to put full debugging hooks in your own code, including
131+
debug information when matplotlib starts up, then the way to do so is to
132+
insert the following *before* any calls to ``import matplotlib``::
127133

128134
import logging
129135
logging.basicConfig(level=logging.DEBUG)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:orphan:
2+
3+
New methods for verbose logging
4+
-------------------------------
5+
6+
If more debugging information is required, the user can call
7+
the `.pyplot.set_loglevel` method.

lib/matplotlib/__init__.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,35 @@ def _check_versions():
207207
sys.argv = ['modpython']
208208

209209

210-
_verbose_msg = """\
211-
matplotlib.verbose is deprecated;
212-
Command line argument --verbose-LEVEL is deprecated.
213-
This functionality is now provided by the standard
214-
python logging library. To get more (or less) logging output:
215-
import logging
216-
logger = logging.getLogger('matplotlib')
217-
logger.set_level(logging.INFO)"""
210+
def set_loglevel(level='info'):
211+
"""
212+
Shortcut to set the logging level of the logging module.
213+
214+
Parameters
215+
----------
216+
level : str or bool
217+
If True set logging level to "INFO" for matplotlib module.
218+
If FALSE set logging level to "WARNING" for matplotlib module (this
219+
is the default level if ``set_loglevel`` is not called). If a string,
220+
must be one of ['warning', 'info', 'debug'], in order of increasing
221+
verbosity.
222+
223+
Notes
224+
-----
225+
This is the same as the standard python `logging` module::
226+
227+
import logging
228+
229+
_log = logging.getLogger(__name__)
230+
_log.setLevel(logging.INFO) # or logging.WARNING, logging.INFO
231+
232+
"""
233+
234+
if level is True:
235+
level = 'info'
236+
if level is False:
237+
level = 'warning'
238+
_set_logger_verbose_level(level_str=level.lower())
218239

219240

220241
def _set_logger_verbose_level(level_str='silent', file_str='sys.stdout'):

lib/matplotlib/pyplot.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,32 @@ def colormaps():
19971997
return sorted(cm.cmap_d)
19981998

19991999

2000+
def set_loglevel(level='info'):
2001+
"""
2002+
Shortcut to set the debugging level of the logging module.
2003+
2004+
Parameters
2005+
----------
2006+
level : str or bool (optional)
2007+
If *True* (default) set logging level to "INFO" for matplotlib module.
2008+
If *False* set logging level to "WARNING" for matplotlib module (this
2009+
is the default level if ``verbose`` is not called). If a string, must
2010+
be one of ['warning', 'info', 'debug'], in order of increasing
2011+
verbosity.
2012+
2013+
Notes
2014+
-----
2015+
This is the same as the standard python `logging` module::
2016+
2017+
import logging
2018+
2019+
_log = logging.getLogger(__name__)
2020+
_log.setLevel(logging.DEBUG) # or logging.WARNING, logging.INFO
2021+
2022+
"""
2023+
matplotlib.set_loglevel(level=level)
2024+
2025+
20002026
def _setup_pyplot_info_docstrings():
20012027
"""
20022028
Generates the plotting docstring.

0 commit comments

Comments
 (0)