@@ -244,7 +244,7 @@ def _set_logger_verbose_level(level_str='silent', file_str='sys.stdout'):
244244fileo = open (file_str ,'w' )
245245# if this fails, we will just write to stdout
246246except IOError :
247- warnings . warn ('could not open log file "{0}"'
247+ logging . warning ('could not open log file "{0}"'
248248'for writing. Check your '
249249'matplotlibrc' .format (file_str ))
250250console = logging .StreamHandler (fileo )
@@ -307,8 +307,10 @@ def set_level(self, level):
307307if self ._commandLineVerbose is not None :
308308level = self ._commandLineVerbose
309309if level not in self .levels :
310- warnings .warn ('matplotlib: unrecognized --verbose-* string "%s".'
311- ' Legal values are %s' % (level ,self .levels ))
310+ cbook ._warn_external (
311+ 'matplotlib: unrecognized --verbose-* '
312+ 'string "%s". Legal values are %s' % (
313+ level ,self .levels ))
312314else :
313315self .level = level
314316
@@ -487,9 +489,10 @@ def checkdep_ps_distiller(s):
487489gs_exec ,gs_v = checkdep_ghostscript ()
488490if not gs_exec :
489491flag = False
490- warnings .warn ('matplotlibrc ps.usedistiller option can not be used '
491- 'unless ghostscript 9.0 or later is installed on your '
492- 'system' )
492+
493+ logging .warning (('matplotlibrc ps.usedistiller option can not be used '
494+ 'unless ghostscript-%s or later is installed on your '
495+ 'system' )% gs_req )
493496
494497if s == 'xpdf' :
495498pdftops_req = '3.0'
@@ -502,7 +505,7 @@ def checkdep_ps_distiller(s):
502505pass
503506else :
504507flag = False
505- warnings . warn (('matplotlibrc ps.usedistiller can not be set to '
508+ logging . warning (('matplotlibrc ps.usedistiller can not be set to '
506509'xpdf unless xpdf-%s or later is installed on '
507510'your system' )% pdftops_req )
508511
@@ -522,20 +525,20 @@ def checkdep_usetex(s):
522525
523526if shutil .which ("tex" )is None :
524527flag = False
525- warnings . warn ('matplotlibrc text.usetex option can not be used unless '
528+ logging . warning ('matplotlibrc text.usetex option can not be used unless '
526529'TeX is installed on your system' )
527530
528531dvipng_v = checkdep_dvipng ()
529532if not compare_versions (dvipng_v ,dvipng_req ):
530533flag = False
531- warnings . warn ('matplotlibrc text.usetex can not be used with *Agg '
534+ logging . warning ('matplotlibrc text.usetex can not be used with *Agg '
532535'backend unless dvipng-%s or later is installed on '
533536'your system' % dvipng_req )
534537
535538gs_exec ,gs_v = checkdep_ghostscript ()
536539if not compare_versions (gs_v ,gs_req ):
537540flag = False
538- warnings . warn ('matplotlibrc text.usetex can not be used unless '
541+ logging . warning ('matplotlibrc text.usetex can not be used unless '
539542'ghostscript-%s or later is installed on your system'
540543% gs_req )
541544
@@ -954,17 +957,17 @@ def _rc_params_in_file(fname, fail_on_error=False):
954957tup = strippedline .split (':' ,1 )
955958if len (tup )!= 2 :
956959error_details = _error_details_fmt % (cnt ,line ,fname )
957- warnings . warn ('Illegal %s' % error_details )
960+ logging . warning ('Illegal %s' % error_details )
958961continue
959962key ,val = tup
960963key = key .strip ()
961964val = val .strip ()
962965if key in rc_temp :
963- warnings . warn ('Duplicate key in file "%s", line #%d' %
966+ logging . warning ('Duplicate key in file "%s", line #%d' %
964967 (fname ,cnt ))
965968rc_temp [key ]= (val ,line ,cnt )
966969except UnicodeDecodeError :
967- warnings . warn (
970+ logging . warning (
968971 ('Cannot decode configuration file %s with '
969972'encoding %s, check LANG and LC_* variables' )
970973% (fname ,locale .getpreferredencoding (do_setlocale = False )or
@@ -983,7 +986,7 @@ def _rc_params_in_file(fname, fail_on_error=False):
983986config [key ]= val # try to convert to proper type or skip
984987except Exception as msg :
985988error_details = _error_details_fmt % (cnt ,line ,fname )
986- warnings . warn ('Bad val "%s" on %s\n \t %s' %
989+ logging . warning ('Bad val "%s" on %s\n \t %s' %
987990 (val ,error_details ,msg ))
988991
989992for key , (val ,line ,cnt )in rc_temp .items ():
@@ -995,7 +998,7 @@ def _rc_params_in_file(fname, fail_on_error=False):
995998config [key ]= val # try to convert to proper type or skip
996999except Exception as msg :
9971000error_details = _error_details_fmt % (cnt ,line ,fname )
998- warnings . warn ('Bad val "%s" on %s\n \t %s' %
1001+ logging . warning ('Bad val "%s" on %s\n \t %s' %
9991002 (val ,error_details ,msg ))
10001003elif key in _deprecated_ignore_map :
10011004version ,alt_key = _deprecated_ignore_map [key ]
@@ -1338,10 +1341,9 @@ def use(arg, warn=True, force=False):
13381341# If we are going to force the switch, never warn, else, if warn
13391342# is True, then direct users to `plt.switch_backend`
13401343if (not force )and warn :
1341- warnings . warn (
1344+ cbook . _warn_external (
13421345 ("matplotlib.pyplot as already been imported, "
1343- "this call will have no effect." ),
1344- stacklevel = 2 )
1346+ "this call will have no effect." ))
13451347
13461348# if we are going to force switching the backend, pull in
13471349# `switch_backend` from pyplot. This will only happen if
@@ -1421,7 +1423,7 @@ def _init_tests():
14211423from matplotlib import ft2font
14221424if (ft2font .__freetype_version__ != LOCAL_FREETYPE_VERSION or
14231425ft2font .__freetype_build_type__ != 'local' ):
1424- warnings . warn (
1426+ logging . warning (
14251427"Matplotlib is not built with the correct FreeType version to run "
14261428"tests. Set local_freetype=True in setup.cfg and rebuild. "
14271429"Expect many image comparison failures below. "
@@ -1430,9 +1432,7 @@ def _init_tests():
14301432"Freetype build type is {2}local" .format (
14311433LOCAL_FREETYPE_VERSION ,
14321434ft2font .__freetype_version__ ,
1433- "" if ft2font .__freetype_build_type__ == 'local' else "not "
1434- )
1435- )
1435+ "" if ft2font .__freetype_build_type__ == 'local' else "not " ))
14361436
14371437try :
14381438import pytest
@@ -1762,12 +1762,13 @@ def inner(ax, *args, data=None, **kwargs):
17621762elif label_namer in kwargs :
17631763kwargs ['label' ]= get_label (kwargs [label_namer ],label )
17641764else :
1765- warnings . warn (
1765+ cbook . _warn_external (
17661766"Tried to set a label via parameter %r in func %r but "
17671767"couldn't find such an argument.\n "
17681768"(This is a programming error, please report to "
1769- "the Matplotlib list!)" % (label_namer ,func .__name__ ),
1770- RuntimeWarning ,stacklevel = 2 )
1769+ "the Matplotlib list!)" % (label_namer ,
1770+ func .__name__ ),
1771+ RuntimeWarning )
17711772return func (ax ,* args ,** kwargs )
17721773
17731774inner .__doc__ = _add_data_doc (inner .__doc__ ,