@@ -244,9 +244,8 @@ 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}"'
248- 'for writing. Check your '
249- 'matplotlibrc' .format (file_str ))
247+ _log .warning ('could not open log file "{0}" for writing. '
248+ 'Check your matplotlibrc' .format (file_str ))
250249console = logging .StreamHandler (fileo )
251250console .setLevel (newlev )
252251_log .addHandler (console )
@@ -307,8 +306,9 @@ def set_level(self, level):
307306if self ._commandLineVerbose is not None :
308307level = self ._commandLineVerbose
309308if level not in self .levels :
310- warnings .warn ('matplotlib: unrecognized --verbose-* string "%s".'
311- ' Legal values are %s' % (level ,self .levels ))
309+ cbook ._warn_external ('matplotlib: unrecognized --verbose-* '
310+ 'string "%s". Legal values are %s' %
311+ (level ,self .levels ))
312312else :
313313self .level = level
314314
@@ -487,9 +487,9 @@ def checkdep_ps_distiller(s):
487487gs_exec ,gs_v = checkdep_ghostscript ()
488488if not gs_exec :
489489flag = 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' )
490+ _log . warning ('matplotlibrc ps.usedistiller option can not be used '
491+ 'unless ghostscript 9.0 or later is installed on your '
492+ 'system' )
493493
494494if s == 'xpdf' :
495495pdftops_req = '3.0'
@@ -502,9 +502,9 @@ def checkdep_ps_distiller(s):
502502pass
503503else :
504504flag = False
505- warnings . warn (('matplotlibrc ps.usedistiller can not be set to '
506- 'xpdf unless xpdf-%s or later is installed on '
507- 'your system' )% pdftops_req )
505+ _log . warning (('matplotlibrc ps.usedistiller can not be set to '
506+ 'xpdf unless xpdf-%s or later is installed on '
507+ 'your system' )% pdftops_req )
508508
509509if flag :
510510return s
@@ -522,22 +522,22 @@ def checkdep_usetex(s):
522522
523523if shutil .which ("tex" )is None :
524524flag = False
525- warnings . warn ('matplotlibrc text.usetex option can not be used unless '
526- 'TeX is installed on your system' )
525+ _log . warning ('matplotlibrc text.usetex option can not be used unless '
526+ 'TeX is installed on your system' )
527527
528528dvipng_v = checkdep_dvipng ()
529529if not compare_versions (dvipng_v ,dvipng_req ):
530530flag = False
531- warnings . warn ('matplotlibrc text.usetex can not be used with *Agg '
532- 'backend unless dvipng-%s or later is installed on '
533- 'your system' % dvipng_req )
531+ _log . warning ('matplotlibrc text.usetex can not be used with *Agg '
532+ 'backend unless dvipng-%s or later is installed on '
533+ 'your system' % dvipng_req )
534534
535535gs_exec ,gs_v = checkdep_ghostscript ()
536536if not compare_versions (gs_v ,gs_req ):
537537flag = False
538- warnings . warn ('matplotlibrc text.usetex can not be used unless '
539- 'ghostscript-%s or later is installed on your system'
540- % gs_req )
538+ _log . warning ('matplotlibrc text.usetex can not be used unless '
539+ 'ghostscript-%s or later is installed on your system'
540+ % gs_req )
541541
542542return flag
543543
@@ -962,17 +962,17 @@ def _rc_params_in_file(fname, fail_on_error=False):
962962tup = strippedline .split (':' ,1 )
963963if len (tup )!= 2 :
964964error_details = _error_details_fmt % (cnt ,line ,fname )
965- warnings . warn ('Illegal %s' % error_details )
965+ _log . warning ('Illegal %s' % error_details )
966966continue
967967key ,val = tup
968968key = key .strip ()
969969val = val .strip ()
970970if key in rc_temp :
971- warnings . warn ('Duplicate key in file "%s", line #%d' %
972- (fname ,cnt ))
971+ _log . warning ('Duplicate key in file "%s", line #%d' %
972+ (fname ,cnt ))
973973rc_temp [key ]= (val ,line ,cnt )
974974except UnicodeDecodeError :
975- warnings . warn (
975+ _log . warning (
976976 ('Cannot decode configuration file %s with '
977977'encoding %s, check LANG and LC_* variables' )
978978% (fname ,locale .getpreferredencoding (do_setlocale = False )or
@@ -991,8 +991,8 @@ def _rc_params_in_file(fname, fail_on_error=False):
991991config [key ]= val # try to convert to proper type or skip
992992except Exception as msg :
993993error_details = _error_details_fmt % (cnt ,line ,fname )
994- warnings . warn ('Bad val "%s" on %s\n \t %s' %
995- (val ,error_details ,msg ))
994+ _log . warning ('Bad val "%s" on %s\n \t %s' %
995+ (val ,error_details ,msg ))
996996
997997for key , (val ,line ,cnt )in rc_temp .items ():
998998if key in defaultParams :
@@ -1003,8 +1003,8 @@ def _rc_params_in_file(fname, fail_on_error=False):
10031003config [key ]= val # try to convert to proper type or skip
10041004except Exception as msg :
10051005error_details = _error_details_fmt % (cnt ,line ,fname )
1006- warnings . warn ('Bad val "%s" on %s\n \t %s' %
1007- (val ,error_details ,msg ))
1006+ _log . warning ('Bad val "%s" on %s\n \t %s' %
1007+ (val ,error_details ,msg ))
10081008elif key in _deprecated_ignore_map :
10091009version ,alt_key = _deprecated_ignore_map [key ]
10101010cbook .warn_deprecated (
@@ -1347,10 +1347,9 @@ def use(arg, warn=False, force=True):
13471347# If we are going to force the switch, never warn, else, if warn
13481348# is True, then direct users to `plt.switch_backend`
13491349if (not force )and warn :
1350- warnings . warn (
1350+ cbook . _warn_external (
13511351 ("matplotlib.pyplot as already been imported, "
1352- "this call will have no effect." ),
1353- stacklevel = 2 )
1352+ "this call will have no effect." ))
13541353
13551354# if we are going to force switching the backend, pull in
13561355# `switch_backend` from pyplot. This will only happen if
@@ -1430,7 +1429,7 @@ def _init_tests():
14301429from matplotlib import ft2font
14311430if (ft2font .__freetype_version__ != LOCAL_FREETYPE_VERSION or
14321431ft2font .__freetype_build_type__ != 'local' ):
1433- warnings . warn (
1432+ _log . warning (
14341433"Matplotlib is not built with the correct FreeType version to run "
14351434"tests. Set local_freetype=True in setup.cfg and rebuild. "
14361435"Expect many image comparison failures below. "
@@ -1439,9 +1438,7 @@ def _init_tests():
14391438"Freetype build type is {2}local" .format (
14401439LOCAL_FREETYPE_VERSION ,
14411440ft2font .__freetype_version__ ,
1442- "" if ft2font .__freetype_build_type__ == 'local' else "not "
1443- )
1444- )
1441+ "" if ft2font .__freetype_build_type__ == 'local' else "not " ))
14451442
14461443try :
14471444import pytest
@@ -1771,12 +1768,12 @@ def inner(ax, *args, data=None, **kwargs):
17711768elif label_namer in kwargs :
17721769kwargs ['label' ]= get_label (kwargs [label_namer ],label )
17731770else :
1774- warnings . warn (
1771+ cbook . _warn_external (
17751772"Tried to set a label via parameter %r in func %r but "
1776- "couldn't find such an argument.\n "
1777- "(This is a programming error, please report to "
1778- "the Matplotlib list!)" % (label_namer ,func .__name__ ),
1779- RuntimeWarning , stacklevel = 2 )
1773+ "couldn't find such an argument.\n (This is a "
1774+ "programming error, please report to the Matplotlib "
1775+ "list!)" % (label_namer ,func .__name__ ),
1776+ RuntimeWarning )
17801777return func (ax ,* args ,** kwargs )
17811778
17821779inner .__doc__ = _add_data_doc (inner .__doc__ ,