@@ -244,7 +244,7 @@ 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}"'
247
+ logging . warning ('could not open log file "{0}"'
248
248
'for writing. Check your '
249
249
'matplotlibrc' .format (file_str ))
250
250
console = logging .StreamHandler (fileo )
@@ -307,8 +307,10 @@ def set_level(self, level):
307
307
if self ._commandLineVerbose is not None :
308
308
level = self ._commandLineVerbose
309
309
if 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-* string "%s". Legal '
312
+ 'values are %s' % (
313
+ level , self .levels ))
312
314
else :
313
315
self .level = level
314
316
@@ -487,7 +489,8 @@ def checkdep_ps_distiller(s):
487
489
gs_exec , gs_v = checkdep_ghostscript ()
488
490
if not gs_exec :
489
491
flag = False
490
- warnings .warn ('matplotlibrc ps.usedistiller option can not be used '
492
+
493
+ logging .warning ('matplotlibrc ps.usedistiller option can not be used '
491
494
'unless ghostscript 9.0 or later is installed on your '
492
495
'system' )
493
496
@@ -502,7 +505,7 @@ def checkdep_ps_distiller(s):
502
505
pass
503
506
else :
504
507
flag = False
505
- warnings . warn (('matplotlibrc ps.usedistiller can not be set to '
508
+ logging . warning (('matplotlibrc ps.usedistiller can not be set to '
506
509
'xpdf unless xpdf-%s or later is installed on '
507
510
'your system' ) % pdftops_req )
508
511
@@ -522,20 +525,21 @@ def checkdep_usetex(s):
522
525
523
526
if shutil .which ("tex" ) is None :
524
527
flag = False
525
- warnings .warn ('matplotlibrc text.usetex option can not be used unless '
526
- 'TeX is installed on your system' )
528
+ logging .warning (
529
+ 'matplotlibrc text.usetex option can not be used unless TeX is '
530
+ 'installed on your system' )
527
531
528
532
dvipng_v = checkdep_dvipng ()
529
533
if not compare_versions (dvipng_v , dvipng_req ):
530
534
flag = False
531
- warnings . warn ('matplotlibrc text.usetex can not be used with *Agg '
535
+ logging . warning ('matplotlibrc text.usetex can not be used with *Agg '
532
536
'backend unless dvipng-%s or later is installed on '
533
537
'your system' % dvipng_req )
534
538
535
539
gs_exec , gs_v = checkdep_ghostscript ()
536
540
if not compare_versions (gs_v , gs_req ):
537
541
flag = False
538
- warnings . warn ('matplotlibrc text.usetex can not be used unless '
542
+ logging . warning ('matplotlibrc text.usetex can not be used unless '
539
543
'ghostscript-%s or later is installed on your system'
540
544
% gs_req )
541
545
@@ -954,17 +958,17 @@ def _rc_params_in_file(fname, fail_on_error=False):
954
958
tup = strippedline .split (':' , 1 )
955
959
if len (tup ) != 2 :
956
960
error_details = _error_details_fmt % (cnt , line , fname )
957
- warnings . warn ('Illegal %s' % error_details )
961
+ logging . warning ('Illegal %s' % error_details )
958
962
continue
959
963
key , val = tup
960
964
key = key .strip ()
961
965
val = val .strip ()
962
966
if key in rc_temp :
963
- warnings . warn ('Duplicate key in file "%s", line #%d' %
967
+ logging . warning ('Duplicate key in file "%s", line #%d' %
964
968
(fname , cnt ))
965
969
rc_temp [key ] = (val , line , cnt )
966
970
except UnicodeDecodeError :
967
- warnings . warn (
971
+ logging . warning (
968
972
('Cannot decode configuration file %s with '
969
973
'encoding %s, check LANG and LC_* variables' )
970
974
% (fname , locale .getpreferredencoding (do_setlocale = False ) or
@@ -983,7 +987,7 @@ def _rc_params_in_file(fname, fail_on_error=False):
983
987
config [key ] = val # try to convert to proper type or skip
984
988
except Exception as msg :
985
989
error_details = _error_details_fmt % (cnt , line , fname )
986
- warnings . warn ('Bad val "%s" on %s\n \t %s' %
990
+ logging . warning ('Bad val "%s" on %s\n \t %s' %
987
991
(val , error_details , msg ))
988
992
989
993
for key , (val , line , cnt ) in rc_temp .items ():
@@ -995,7 +999,7 @@ def _rc_params_in_file(fname, fail_on_error=False):
995
999
config [key ] = val # try to convert to proper type or skip
996
1000
except Exception as msg :
997
1001
error_details = _error_details_fmt % (cnt , line , fname )
998
- warnings . warn ('Bad val "%s" on %s\n \t %s' %
1002
+ logging . warning ('Bad val "%s" on %s\n \t %s' %
999
1003
(val , error_details , msg ))
1000
1004
elif key in _deprecated_ignore_map :
1001
1005
version , alt_key = _deprecated_ignore_map [key ]
@@ -1338,10 +1342,9 @@ def use(arg, warn=True, force=False):
1338
1342
# If we are going to force the switch, never warn, else, if warn
1339
1343
# is True, then direct users to `plt.switch_backend`
1340
1344
if (not force ) and warn :
1341
- warnings . warn (
1345
+ cbook . _warn_external (
1342
1346
("matplotlib.pyplot as already been imported, "
1343
- "this call will have no effect." ),
1344
- stacklevel = 2 )
1347
+ "this call will have no effect." ))
1345
1348
1346
1349
# if we are going to force switching the backend, pull in
1347
1350
# `switch_backend` from pyplot. This will only happen if
@@ -1421,7 +1424,7 @@ def _init_tests():
1421
1424
from matplotlib import ft2font
1422
1425
if (ft2font .__freetype_version__ != LOCAL_FREETYPE_VERSION or
1423
1426
ft2font .__freetype_build_type__ != 'local' ):
1424
- warnings . warn (
1427
+ logging . warning (
1425
1428
"Matplotlib is not built with the correct FreeType version to run "
1426
1429
"tests. Set local_freetype=True in setup.cfg and rebuild. "
1427
1430
"Expect many image comparison failures below. "
@@ -1430,9 +1433,7 @@ def _init_tests():
1430
1433
"Freetype build type is {2}local" .format (
1431
1434
LOCAL_FREETYPE_VERSION ,
1432
1435
ft2font .__freetype_version__ ,
1433
- "" if ft2font .__freetype_build_type__ == 'local' else "not "
1434
- )
1435
- )
1436
+ "" if ft2font .__freetype_build_type__ == 'local' else "not " ))
1436
1437
1437
1438
try :
1438
1439
import pytest
@@ -1762,12 +1763,13 @@ def inner(ax, *args, data=None, **kwargs):
1762
1763
elif label_namer in kwargs :
1763
1764
kwargs ['label' ] = get_label (kwargs [label_namer ], label )
1764
1765
else :
1765
- warnings . warn (
1766
+ cbook . _warn_external (
1766
1767
"Tried to set a label via parameter %r in func %r but "
1767
1768
"couldn't find such an argument.\n "
1768
1769
"(This is a programming error, please report to "
1769
- "the Matplotlib list!)" % (label_namer , func .__name__ ),
1770
- RuntimeWarning , stacklevel = 2 )
1770
+ "the Matplotlib list!)" % (label_namer ,
1771
+ func .__name__ ),
1772
+ RuntimeWarning )
1771
1773
return func (ax , * args , ** kwargs )
1772
1774
1773
1775
inner .__doc__ = _add_data_doc (inner .__doc__ ,
0 commit comments