50
50
51
51
52
52
class ValidateInStrings :
53
- def __init__ (self , key , valid , ignorecase = False ):
53
+ def __init__ (self , key , valid , ignorecase = False , * ,
54
+ _deprecated_since = None ):
54
55
"""*valid* is a list of legal strings."""
55
56
self .key = key
56
57
self .ignorecase = ignorecase
58
+ self ._deprecated_since = _deprecated_since
57
59
58
60
def func (s ):
59
61
if ignorecase :
@@ -63,6 +65,10 @@ def func(s):
63
65
self .valid = {func (k ): k for k in valid }
64
66
65
67
def __call__ (self , s ):
68
+ if self ._deprecated_since :
69
+ name , = (k for k , v in globals ().items () if v is self )
70
+ cbook .warn_deprecated (
71
+ self ._deprecated_since , name = name , obj_type = "function" )
66
72
if self .ignorecase :
67
73
s = s .lower ()
68
74
if s in self .valid :
@@ -365,7 +371,7 @@ def validate_color(s):
365
371
validate_colorlist = _listify_validator (
366
372
validate_color , allow_stringlist = True , doc = 'return a list of colorspecs' )
367
373
validate_orientation = ValidateInStrings (
368
- 'orientation' , ['landscape' , 'portrait' ])
374
+ 'orientation' , ['landscape' , 'portrait' ], _deprecated_since = "3.3" )
369
375
370
376
371
377
def validate_aspect (s ):
@@ -421,15 +427,15 @@ def validate_font_properties(s):
421
427
422
428
validate_fontset = ValidateInStrings (
423
429
'fontset' ,
424
- ['dejavusans' , 'dejavuserif' , 'cm' , 'stix' , 'stixsans' , 'custom' ])
430
+ ['dejavusans' , 'dejavuserif' , 'cm' , 'stix' , 'stixsans' , 'custom' ],
431
+ _deprecated_since = "3.3" )
425
432
validate_mathtext_default = ValidateInStrings (
426
- 'default' , "rm cal it tt sf bf default bb frak scr regular" .split ())
427
-
428
-
433
+ 'default' , "rm cal it tt sf bf default bb frak scr regular" .split (),
434
+ _deprecated_since = "3.3" )
429
435
_validate_alignment = ValidateInStrings (
430
436
'alignment' ,
431
- ['center' , 'top' , 'bottom' , 'baseline' ,
432
- 'center_baseline' ] )
437
+ ['center' , 'top' , 'bottom' , 'baseline' , 'center_baseline' ],
438
+ _deprecated_since = "3.3" )
433
439
434
440
435
441
def validate_whiskers (s ):
@@ -648,7 +654,8 @@ def validate_markevery(s):
648
654
'upper center' ,
649
655
'center' ], ignorecase = True )
650
656
651
- validate_svg_fonttype = ValidateInStrings ('svg.fonttype' , ['none' , 'path' ])
657
+ validate_svg_fonttype = ValidateInStrings (
658
+ 'svg.fonttype' , ['none' , 'path' ], _deprecated_since = "3.3" )
652
659
653
660
654
661
def validate_hinting (s ):
@@ -663,8 +670,9 @@ def validate_hinting(s):
663
670
raise ValueError ("hinting should be 'auto', 'native', 'either' or 'none'" )
664
671
665
672
666
- validate_pgf_texsystem = ValidateInStrings ('pgf.texsystem' ,
667
- ['xelatex' , 'lualatex' , 'pdflatex' ])
673
+ validate_pgf_texsystem = ValidateInStrings (
674
+ 'pgf.texsystem' , ['xelatex' , 'lualatex' , 'pdflatex' ],
675
+ _deprecated_since = "3.3" )
668
676
669
677
670
678
def validate_movie_writer (s ):
@@ -678,12 +686,13 @@ def validate_movie_writer(s):
678
686
679
687
680
688
validate_movie_frame_fmt = ValidateInStrings ('animation.frame_format' ,
681
- ['png' , 'jpeg' , 'tiff' , 'raw' , 'rgba' ])
689
+ ['png' , 'jpeg' , 'tiff' , 'raw' , 'rgba' ], _deprecated_since = "3.3" )
682
690
683
- validate_axis_locator = ValidateInStrings ('major' , ['minor' , 'both' , 'major' ])
691
+ validate_axis_locator = ValidateInStrings (
692
+ 'major' , ['minor' , 'both' , 'major' ], _deprecated_since = "3.3" )
684
693
685
694
validate_movie_html_fmt = ValidateInStrings ('animation.html' ,
686
- ['html5' , 'jshtml' , 'none' ])
695
+ ['html5' , 'jshtml' , 'none' ], _deprecated_since = "3.3" )
687
696
688
697
689
698
def validate_bbox (s ):
@@ -736,7 +745,8 @@ def _validate_greaterequal0_lessequal1(s):
736
745
}
737
746
738
747
739
- validate_grid_axis = ValidateInStrings ('axes.grid.axis' , ['x' , 'y' , 'both' ])
748
+ validate_grid_axis = ValidateInStrings (
749
+ 'axes.grid.axis' , ['x' , 'y' , 'both' ], _deprecated_since = "3.3" )
740
750
741
751
742
752
def validate_hatch (s ):
@@ -984,12 +994,8 @@ def validate_webagg_address(s):
984
994
raise ValueError ("'webagg.address' is not a valid IP address" )
985
995
986
996
987
- validate_axes_titlelocation = ValidateInStrings ('axes.titlelocation' ,
988
- ['left' , 'center' , 'right' ])
989
- _validate_xaxis_labellocation = ValidateInStrings ('xaxis.labellocation' ,
990
- ['left' , 'center' , 'right' ])
991
- _validate_yaxis_labellocation = ValidateInStrings ('yaxis.labellocation' ,
992
- ['bottom' , 'center' , 'top' ])
997
+ validate_axes_titlelocation = ValidateInStrings (
998
+ 'axes.titlelocation' , ['left' , 'center' , 'right' ], _deprecated_since = "3.3" )
993
999
994
1000
995
1001
# a map from key -> value, converter
@@ -1137,16 +1143,19 @@ def validate_webagg_address(s):
1137
1143
'mathtext.it' : ['sans:italic' , validate_font_properties ],
1138
1144
'mathtext.bf' : ['sans:bold' , validate_font_properties ],
1139
1145
'mathtext.sf' : ['sans' , validate_font_properties ],
1140
- 'mathtext.fontset' : ['dejavusans' , validate_fontset ],
1141
- 'mathtext.default' : ['it' , validate_mathtext_default ],
1146
+ 'mathtext.fontset' : [
1147
+ 'dejavusans' ,
1148
+ ['dejavusans' , 'dejavuserif' , 'cm' , 'stix' , 'stixsans' , 'custom' ]],
1149
+ 'mathtext.default' : [
1150
+ 'it' ,
1151
+ ['rm' , 'cal' , 'it' , 'tt' , 'sf' , 'bf' , 'default' , 'bb' , 'frak' , 'scr' , 'regular' ]],
1142
1152
'mathtext.fallback_to_cm' : [True , validate_bool ],
1143
1153
1144
1154
'image.aspect' : ['equal' , validate_aspect ], # equal, auto, a number
1145
1155
'image.interpolation' : ['antialiased' , validate_string ],
1146
1156
'image.cmap' : ['viridis' , validate_string ], # gray, jet, etc.
1147
1157
'image.lut' : [256 , validate_int ], # lookup table
1148
- 'image.origin' : ['upper' ,
1149
- ValidateInStrings ('image.origin' , ['upper' , 'lower' ])],
1158
+ 'image.origin' : ['upper' , ['upper' , 'lower' ]],
1150
1159
'image.resample' : [True , validate_bool ],
1151
1160
# Specify whether vector graphics backends will combine all images on a
1152
1161
# set of axes into a single composite image
@@ -1160,8 +1169,8 @@ def validate_webagg_address(s):
1160
1169
'errorbar.capsize' : [0 , validate_float ],
1161
1170
1162
1171
# axis props
1163
- 'xaxis.labellocation' : ['center' , _validate_xaxis_labellocation ], # alignment of x axis title
1164
- 'yaxis.labellocation' : ['center' , _validate_yaxis_labellocation ], # alignment of y axis title
1172
+ 'xaxis.labellocation' : ['center' , [ 'left' , 'center' , 'right' ] ], # alignment of x axis title
1173
+ 'yaxis.labellocation' : ['center' , [ 'bottom' , 'center' , 'top' ] ], # alignment of y axis title
1165
1174
1166
1175
# axes props
1167
1176
'axes.axisbelow' : ['line' , validate_axisbelow ],
@@ -1176,16 +1185,14 @@ def validate_webagg_address(s):
1176
1185
1177
1186
'axes.titlesize' : ['large' , validate_fontsize ], # fontsize of the
1178
1187
# axes title
1179
- 'axes.titlelocation' : ['center' , validate_axes_titlelocation ], # alignment of axes title
1188
+ 'axes.titlelocation' : ['center' , [ 'left' , 'center' , 'right' ] ], # alignment of axes title
1180
1189
'axes.titleweight' : ['normal' , validate_fontweight ], # font weight of axes title
1181
1190
'axes.titlecolor' : ['auto' , validate_color_or_auto ], # font color of axes title
1182
1191
'axes.titlepad' : [6.0 , validate_float ], # pad from axes top to title in points
1183
1192
'axes.grid' : [False , validate_bool ], # display grid or not
1184
- 'axes.grid.which' : ['major' , validate_axis_locator ], # set whether the gid are by
1185
- # default draw on 'major'
1186
- # 'minor' or 'both' kind of
1187
- # axis locator
1188
- 'axes.grid.axis' : ['both' , validate_grid_axis ], # grid type:
1193
+ 'axes.grid.which' : ['major' , ['minor' , 'both' , 'major' ]], # set whether the grid is drawn on
1194
+ # 'major' 'minor' or 'both' ticks
1195
+ 'axes.grid.axis' : ['both' , ['x' , 'y' , 'both' ]], # grid type:
1189
1196
# 'x', 'y', or 'both'
1190
1197
'axes.labelsize' : ['medium' , validate_fontsize ], # fontsize of the
1191
1198
# x any y labels
@@ -1214,9 +1221,7 @@ def validate_webagg_address(s):
1214
1221
validate_cycler ],
1215
1222
# If 'data', axes limits are set close to the data.
1216
1223
# If 'round_numbers' axes limits are set to the nearest round numbers.
1217
- 'axes.autolimit_mode' : [
1218
- 'data' ,
1219
- ValidateInStrings ('autolimit_mode' , ['data' , 'round_numbers' ])],
1224
+ 'axes.autolimit_mode' : ['data' , ['data' , 'round_numbers' ]],
1220
1225
'axes.xmargin' : [0.05 , _range_validators ["0 <= x <= 1" ]],
1221
1226
'axes.ymargin' : [0.05 , _range_validators ["0 <= x <= 1" ]],
1222
1227
@@ -1291,7 +1296,8 @@ def validate_webagg_address(s):
1291
1296
# fontsize of the xtick labels
1292
1297
'xtick.labelsize' : ['medium' , validate_fontsize ],
1293
1298
'xtick.direction' : ['out' , validate_string ], # direction of xticks
1294
- 'xtick.alignment' : ["center" , _validate_alignment ],
1299
+ 'xtick.alignment' : ['center' ,
1300
+ ['center' , 'top' , 'bottom' , 'baseline' , 'center_baseline' ]],
1295
1301
1296
1302
'ytick.left' : [True , validate_bool ], # draw ticks on the left side
1297
1303
'ytick.right' : [False , validate_bool ], # draw ticks on the right side
@@ -1313,7 +1319,8 @@ def validate_webagg_address(s):
1313
1319
# fontsize of the ytick labels
1314
1320
'ytick.labelsize' : ['medium' , validate_fontsize ],
1315
1321
'ytick.direction' : ['out' , validate_string ], # direction of yticks
1316
- 'ytick.alignment' : ["center_baseline" , _validate_alignment ],
1322
+ 'ytick.alignment' : ['center_baseline' ,
1323
+ ['center' , 'top' , 'bottom' , 'baseline' , 'center_baseline' ]],
1317
1324
1318
1325
'grid.color' : ['#b0b0b0' , validate_color ], # grid color
1319
1326
'grid.linestyle' : ['-' , _validate_linestyle ], # solid
@@ -1359,7 +1366,7 @@ def validate_webagg_address(s):
1359
1366
'savefig.dpi' : ['figure' , validate_dpi ], # DPI
1360
1367
'savefig.facecolor' : ['white' , validate_color ],
1361
1368
'savefig.edgecolor' : ['white' , validate_color ],
1362
- 'savefig.orientation' : ['portrait' , validate_orientation ],
1369
+ 'savefig.orientation' : ['portrait' , [ 'landscape' , 'portrait' ] ],
1363
1370
'savefig.jpeg_quality' : [95 , validate_int ],
1364
1371
# value checked by backend at runtime
1365
1372
'savefig.format' : ['png' , _update_savefig_format ],
@@ -1389,7 +1396,7 @@ def validate_webagg_address(s):
1389
1396
'pdf.fonttype' : [3 , validate_fonttype ], # 3 (Type3) or 42 (Truetype)
1390
1397
1391
1398
# choose latex application for creating pdf files (xelatex/lualatex)
1392
- 'pgf.texsystem' : ['xelatex' , validate_pgf_texsystem ],
1399
+ 'pgf.texsystem' : ['xelatex' , [ 'xelatex' , 'lualatex' , 'pdflatex' ] ],
1393
1400
# use matplotlib rc settings for font configuration
1394
1401
'pgf.rcfonts' : [True , validate_bool ],
1395
1402
# provide a custom preamble for the latex process
@@ -1398,7 +1405,7 @@ def validate_webagg_address(s):
1398
1405
# write raster image data directly into the svg file
1399
1406
'svg.image_inline' : [True , validate_bool ],
1400
1407
# True to save all characters as paths in the SVG
1401
- 'svg.fonttype' : ['path' , validate_svg_fonttype ],
1408
+ 'svg.fonttype' : ['path' , [ 'none' , 'path' ] ],
1402
1409
'svg.hashsalt' : [None , validate_string_or_None ],
1403
1410
1404
1411
# set this when you want to generate hardcopy docstring
@@ -1432,15 +1439,15 @@ def validate_webagg_address(s):
1432
1439
'keymap.copy' : [['ctrl+c' , 'cmd+c' ], validate_stringlist ],
1433
1440
1434
1441
# Animation settings
1435
- 'animation.html' : ['none' , validate_movie_html_fmt ],
1442
+ 'animation.html' : ['none' , [ 'html5' , 'jshtml' , 'none' ] ],
1436
1443
# Limit, in MB, of size of base64 encoded animation in HTML
1437
1444
# (i.e. IPython notebook)
1438
1445
'animation.embed_limit' : [20 , validate_float ],
1439
1446
'animation.writer' : ['ffmpeg' , validate_movie_writer ],
1440
1447
'animation.codec' : ['h264' , validate_string ],
1441
1448
'animation.bitrate' : [- 1 , validate_int ],
1442
1449
# Controls image format when frames are written to disk
1443
- 'animation.frame_format' : ['png' , validate_movie_frame_fmt ],
1450
+ 'animation.frame_format' : ['png' , [ 'png' , 'jpeg' , 'tiff' , 'raw' , 'rgba' ] ],
1444
1451
# Additional arguments for HTML writer
1445
1452
'animation.html_args' : [[], validate_stringlist ],
1446
1453
# Path to ffmpeg binary. If just binary name, subprocess uses $PATH.
@@ -1464,3 +1471,12 @@ def validate_webagg_address(s):
1464
1471
# altogether. For that use `matplotlib.style.use('classic')`.
1465
1472
'_internal.classic_mode' : [False , validate_bool ]
1466
1473
}
1474
+
1475
+
1476
+ def _fix_validators ():
1477
+ for k , (default , conv ) in defaultParams .items ():
1478
+ if isinstance (conv , list ):
1479
+ defaultParams [k ] = (default , ValidateInStrings (k , conv ))
1480
+
1481
+
1482
+ _fix_validators ()
0 commit comments