@@ -244,9 +244,8 @@ def _set_logger_verbose_level(level_str='silent', file_str='sys.stdout'):
244
244
fileo = open (file_str , 'w' )
245
245
# if this fails, we will just write to stdout
246
246
except 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 ))
250
249
console = logging .StreamHandler (fileo )
251
250
console .setLevel (newlev )
252
251
_log .addHandler (console )
@@ -307,8 +306,9 @@ def set_level(self, level):
307
306
if self ._commandLineVerbose is not None :
308
307
level = self ._commandLineVerbose
309
308
if 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 ))
312
312
else :
313
313
self .level = level
314
314
@@ -487,9 +487,9 @@ def checkdep_ps_distiller(s):
487
487
gs_exec , gs_v = checkdep_ghostscript ()
488
488
if not gs_exec :
489
489
flag = 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' )
493
493
494
494
if s == 'xpdf' :
495
495
pdftops_req = '3.0'
@@ -502,9 +502,9 @@ def checkdep_ps_distiller(s):
502
502
pass
503
503
else :
504
504
flag = 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 )
508
508
509
509
if flag :
510
510
return s
@@ -522,22 +522,22 @@ def checkdep_usetex(s):
522
522
523
523
if shutil .which ("tex" ) is None :
524
524
flag = 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' )
527
527
528
528
dvipng_v = checkdep_dvipng ()
529
529
if not compare_versions (dvipng_v , dvipng_req ):
530
530
flag = 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 )
534
534
535
535
gs_exec , gs_v = checkdep_ghostscript ()
536
536
if not compare_versions (gs_v , gs_req ):
537
537
flag = 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 )
541
541
542
542
return flag
543
543
@@ -954,17 +954,17 @@ def _rc_params_in_file(fname, fail_on_error=False):
954
954
tup = strippedline .split (':' , 1 )
955
955
if len (tup ) != 2 :
956
956
error_details = _error_details_fmt % (cnt , line , fname )
957
- warnings . warn ('Illegal %s' % error_details )
957
+ _log . warning ('Illegal %s' % error_details )
958
958
continue
959
959
key , val = tup
960
960
key = key .strip ()
961
961
val = val .strip ()
962
962
if key in rc_temp :
963
- warnings . warn ('Duplicate key in file "%s", line #%d' %
963
+ _log . warning ('Duplicate key in file "%s", line #%d' %
964
964
(fname , cnt ))
965
965
rc_temp [key ] = (val , line , cnt )
966
966
except UnicodeDecodeError :
967
- warnings . warn (
967
+ _log . warning (
968
968
('Cannot decode configuration file %s with '
969
969
'encoding %s, check LANG and LC_* variables' )
970
970
% (fname , locale .getpreferredencoding (do_setlocale = False ) or
@@ -983,8 +983,8 @@ def _rc_params_in_file(fname, fail_on_error=False):
983
983
config [key ] = val # try to convert to proper type or skip
984
984
except Exception as msg :
985
985
error_details = _error_details_fmt % (cnt , line , fname )
986
- warnings . warn ('Bad val "%s" on %s\n \t %s' %
987
- (val , error_details , msg ))
986
+ _log . warning ('Bad val "%s" on %s\n \t %s' %
987
+ (val , error_details , msg ))
988
988
989
989
for key , (val , line , cnt ) in rc_temp .items ():
990
990
if key in defaultParams :
@@ -995,8 +995,8 @@ def _rc_params_in_file(fname, fail_on_error=False):
995
995
config [key ] = val # try to convert to proper type or skip
996
996
except Exception as msg :
997
997
error_details = _error_details_fmt % (cnt , line , fname )
998
- warnings . warn ('Bad val "%s" on %s\n \t %s' %
999
- (val , error_details , msg ))
998
+ _log . warning ('Bad val "%s" on %s\n \t %s' %
999
+ (val , error_details , msg ))
1000
1000
elif key in _deprecated_ignore_map :
1001
1001
version , alt_key = _deprecated_ignore_map [key ]
1002
1002
cbook .warn_deprecated (
@@ -1338,10 +1338,9 @@ def use(arg, warn=True, force=False):
1338
1338
# If we are going to force the switch, never warn, else, if warn
1339
1339
# is True, then direct users to `plt.switch_backend`
1340
1340
if (not force ) and warn :
1341
- warnings . warn (
1341
+ cbook . _warn_external (
1342
1342
("matplotlib.pyplot as already been imported, "
1343
- "this call will have no effect." ),
1344
- stacklevel = 2 )
1343
+ "this call will have no effect." ))
1345
1344
1346
1345
# if we are going to force switching the backend, pull in
1347
1346
# `switch_backend` from pyplot. This will only happen if
@@ -1421,7 +1420,7 @@ def _init_tests():
1421
1420
from matplotlib import ft2font
1422
1421
if (ft2font .__freetype_version__ != LOCAL_FREETYPE_VERSION or
1423
1422
ft2font .__freetype_build_type__ != 'local' ):
1424
- warnings . warn (
1423
+ _log . warning (
1425
1424
"Matplotlib is not built with the correct FreeType version to run "
1426
1425
"tests. Set local_freetype=True in setup.cfg and rebuild. "
1427
1426
"Expect many image comparison failures below. "
@@ -1430,9 +1429,7 @@ def _init_tests():
1430
1429
"Freetype build type is {2}local" .format (
1431
1430
LOCAL_FREETYPE_VERSION ,
1432
1431
ft2font .__freetype_version__ ,
1433
- "" if ft2font .__freetype_build_type__ == 'local' else "not "
1434
- )
1435
- )
1432
+ "" if ft2font .__freetype_build_type__ == 'local' else "not " ))
1436
1433
1437
1434
try :
1438
1435
import pytest
@@ -1762,12 +1759,12 @@ def inner(ax, *args, data=None, **kwargs):
1762
1759
elif label_namer in kwargs :
1763
1760
kwargs ['label' ] = get_label (kwargs [label_namer ], label )
1764
1761
else :
1765
- warnings . warn (
1762
+ cbook . _warn_external (
1766
1763
"Tried to set a label via parameter %r in func %r but "
1767
- "couldn't find such an argument.\n "
1768
- "(This is a programming error, please report to "
1769
- "the Matplotlib list!)" % (label_namer , func .__name__ ),
1770
- RuntimeWarning , stacklevel = 2 )
1764
+ "couldn't find such an argument.\n (This is a "
1765
+ "programming error, please report to the Matplotlib "
1766
+ "list!)" % (label_namer , func .__name__ ),
1767
+ RuntimeWarning )
1771
1768
return func (ax , * args , ** kwargs )
1772
1769
1773
1770
inner .__doc__ = _add_data_doc (inner .__doc__ ,
0 commit comments