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,15 +994,13 @@ 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
- # a map from key -> value, converter
1001
+ # A map of key -> [value, converter].
1002
+ # Converters given as lists are converted to ValidateInStrings immediately
1003
+ # below.
996
1004
defaultParams = {
997
1005
'backend' : [_auto_backend_sentinel , validate_backend ],
998
1006
'backend_fallback' : [True , validate_bool ],
@@ -1137,16 +1145,19 @@ def validate_webagg_address(s):
1137
1145
'mathtext.it' : ['sans:italic' , validate_font_properties ],
1138
1146
'mathtext.bf' : ['sans:bold' , validate_font_properties ],
1139
1147
'mathtext.sf' : ['sans' , validate_font_properties ],
1140
- 'mathtext.fontset' : ['dejavusans' , validate_fontset ],
1141
- 'mathtext.default' : ['it' , validate_mathtext_default ],
1148
+ 'mathtext.fontset' : [
1149
+ 'dejavusans' ,
1150
+ ['dejavusans' , 'dejavuserif' , 'cm' , 'stix' , 'stixsans' , 'custom' ]],
1151
+ 'mathtext.default' : [
1152
+ 'it' ,
1153
+ ['rm' , 'cal' , 'it' , 'tt' , 'sf' , 'bf' , 'default' , 'bb' , 'frak' , 'scr' , 'regular' ]],
1142
1154
'mathtext.fallback_to_cm' : [True , validate_bool ],
1143
1155
1144
1156
'image.aspect' : ['equal' , validate_aspect ], # equal, auto, a number
1145
1157
'image.interpolation' : ['antialiased' , validate_string ],
1146
1158
'image.cmap' : ['viridis' , validate_string ], # gray, jet, etc.
1147
1159
'image.lut' : [256 , validate_int ], # lookup table
1148
- 'image.origin' : ['upper' ,
1149
- ValidateInStrings ('image.origin' , ['upper' , 'lower' ])],
1160
+ 'image.origin' : ['upper' , ['upper' , 'lower' ]],
1150
1161
'image.resample' : [True , validate_bool ],
1151
1162
# Specify whether vector graphics backends will combine all images on a
1152
1163
# set of axes into a single composite image
@@ -1160,8 +1171,8 @@ def validate_webagg_address(s):
1160
1171
'errorbar.capsize' : [0 , validate_float ],
1161
1172
1162
1173
# 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
1174
+ 'xaxis.labellocation' : ['center' , [ 'left' , 'center' , 'right' ] ], # alignment of x axis title
1175
+ 'yaxis.labellocation' : ['center' , [ 'bottom' , 'center' , 'top' ] ], # alignment of y axis title
1165
1176
1166
1177
# axes props
1167
1178
'axes.axisbelow' : ['line' , validate_axisbelow ],
@@ -1176,16 +1187,14 @@ def validate_webagg_address(s):
1176
1187
1177
1188
'axes.titlesize' : ['large' , validate_fontsize ], # fontsize of the
1178
1189
# axes title
1179
- 'axes.titlelocation' : ['center' , validate_axes_titlelocation ], # alignment of axes title
1190
+ 'axes.titlelocation' : ['center' , [ 'left' , 'center' , 'right' ] ], # alignment of axes title
1180
1191
'axes.titleweight' : ['normal' , validate_fontweight ], # font weight of axes title
1181
1192
'axes.titlecolor' : ['auto' , validate_color_or_auto ], # font color of axes title
1182
1193
'axes.titlepad' : [6.0 , validate_float ], # pad from axes top to title in points
1183
1194
'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:
1195
+ 'axes.grid.which' : ['major' , ['minor' , 'both' , 'major' ]], # set whether the grid is drawn on
1196
+ # 'major' 'minor' or 'both' ticks
1197
+ 'axes.grid.axis' : ['both' , ['x' , 'y' , 'both' ]], # grid type:
1189
1198
# 'x', 'y', or 'both'
1190
1199
'axes.labelsize' : ['medium' , validate_fontsize ], # fontsize of the
1191
1200
# x any y labels
@@ -1214,9 +1223,7 @@ def validate_webagg_address(s):
1214
1223
validate_cycler ],
1215
1224
# If 'data', axes limits are set close to the data.
1216
1225
# 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' ])],
1226
+ 'axes.autolimit_mode' : ['data' , ['data' , 'round_numbers' ]],
1220
1227
'axes.xmargin' : [0.05 , _range_validators ["0 <= x <= 1" ]],
1221
1228
'axes.ymargin' : [0.05 , _range_validators ["0 <= x <= 1" ]],
1222
1229
@@ -1291,7 +1298,8 @@ def validate_webagg_address(s):
1291
1298
# fontsize of the xtick labels
1292
1299
'xtick.labelsize' : ['medium' , validate_fontsize ],
1293
1300
'xtick.direction' : ['out' , validate_string ], # direction of xticks
1294
- 'xtick.alignment' : ["center" , _validate_alignment ],
1301
+ 'xtick.alignment' : ['center' ,
1302
+ ['center' , 'top' , 'bottom' , 'baseline' , 'center_baseline' ]],
1295
1303
1296
1304
'ytick.left' : [True , validate_bool ], # draw ticks on the left side
1297
1305
'ytick.right' : [False , validate_bool ], # draw ticks on the right side
@@ -1313,7 +1321,8 @@ def validate_webagg_address(s):
1313
1321
# fontsize of the ytick labels
1314
1322
'ytick.labelsize' : ['medium' , validate_fontsize ],
1315
1323
'ytick.direction' : ['out' , validate_string ], # direction of yticks
1316
- 'ytick.alignment' : ["center_baseline" , _validate_alignment ],
1324
+ 'ytick.alignment' : ['center_baseline' ,
1325
+ ['center' , 'top' , 'bottom' , 'baseline' , 'center_baseline' ]],
1317
1326
1318
1327
'grid.color' : ['#b0b0b0' , validate_color ], # grid color
1319
1328
'grid.linestyle' : ['-' , _validate_linestyle ], # solid
@@ -1359,7 +1368,7 @@ def validate_webagg_address(s):
1359
1368
'savefig.dpi' : ['figure' , validate_dpi ], # DPI
1360
1369
'savefig.facecolor' : ['white' , validate_color ],
1361
1370
'savefig.edgecolor' : ['white' , validate_color ],
1362
- 'savefig.orientation' : ['portrait' , validate_orientation ],
1371
+ 'savefig.orientation' : ['portrait' , [ 'landscape' , 'portrait' ] ],
1363
1372
'savefig.jpeg_quality' : [95 , validate_int ],
1364
1373
# value checked by backend at runtime
1365
1374
'savefig.format' : ['png' , _update_savefig_format ],
@@ -1389,7 +1398,7 @@ def validate_webagg_address(s):
1389
1398
'pdf.fonttype' : [3 , validate_fonttype ], # 3 (Type3) or 42 (Truetype)
1390
1399
1391
1400
# choose latex application for creating pdf files (xelatex/lualatex)
1392
- 'pgf.texsystem' : ['xelatex' , validate_pgf_texsystem ],
1401
+ 'pgf.texsystem' : ['xelatex' , [ 'xelatex' , 'lualatex' , 'pdflatex' ] ],
1393
1402
# use matplotlib rc settings for font configuration
1394
1403
'pgf.rcfonts' : [True , validate_bool ],
1395
1404
# provide a custom preamble for the latex process
@@ -1398,7 +1407,7 @@ def validate_webagg_address(s):
1398
1407
# write raster image data directly into the svg file
1399
1408
'svg.image_inline' : [True , validate_bool ],
1400
1409
# True to save all characters as paths in the SVG
1401
- 'svg.fonttype' : ['path' , validate_svg_fonttype ],
1410
+ 'svg.fonttype' : ['path' , [ 'none' , 'path' ] ],
1402
1411
'svg.hashsalt' : [None , validate_string_or_None ],
1403
1412
1404
1413
# set this when you want to generate hardcopy docstring
@@ -1432,15 +1441,15 @@ def validate_webagg_address(s):
1432
1441
'keymap.copy' : [['ctrl+c' , 'cmd+c' ], validate_stringlist ],
1433
1442
1434
1443
# Animation settings
1435
- 'animation.html' : ['none' , validate_movie_html_fmt ],
1444
+ 'animation.html' : ['none' , [ 'html5' , 'jshtml' , 'none' ] ],
1436
1445
# Limit, in MB, of size of base64 encoded animation in HTML
1437
1446
# (i.e. IPython notebook)
1438
1447
'animation.embed_limit' : [20 , validate_float ],
1439
1448
'animation.writer' : ['ffmpeg' , validate_movie_writer ],
1440
1449
'animation.codec' : ['h264' , validate_string ],
1441
1450
'animation.bitrate' : [- 1 , validate_int ],
1442
1451
# Controls image format when frames are written to disk
1443
- 'animation.frame_format' : ['png' , validate_movie_frame_fmt ],
1452
+ 'animation.frame_format' : ['png' , [ 'png' , 'jpeg' , 'tiff' , 'raw' , 'rgba' ] ],
1444
1453
# Additional arguments for HTML writer
1445
1454
'animation.html_args' : [[], validate_stringlist ],
1446
1455
# Path to ffmpeg binary. If just binary name, subprocess uses $PATH.
@@ -1464,3 +1473,7 @@ def validate_webagg_address(s):
1464
1473
# altogether. For that use `matplotlib.style.use('classic')`.
1465
1474
'_internal.classic_mode' : [False , validate_bool ]
1466
1475
}
1476
+ defaultParams = {
1477
+ k : [default ,
1478
+ ValidateInStrings (k , conv ) if isinstance (conv , list ) else conv ]
1479
+ for k , (default , conv ) in defaultParams .items ()}
0 commit comments