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 :
@@ -352,7 +358,7 @@ def validate_color(s):
352
358
validate_colorlist = _listify_validator (
353
359
validate_color , allow_stringlist = True , doc = 'return a list of colorspecs' )
354
360
validate_orientation = ValidateInStrings (
355
- 'orientation' , ['landscape' , 'portrait' ])
361
+ 'orientation' , ['landscape' , 'portrait' ], _deprecated_since = "3.3" )
356
362
357
363
358
364
def validate_aspect (s ):
@@ -408,15 +414,15 @@ def validate_font_properties(s):
408
414
409
415
validate_fontset = ValidateInStrings (
410
416
'fontset' ,
411
- ['dejavusans' , 'dejavuserif' , 'cm' , 'stix' , 'stixsans' , 'custom' ])
417
+ ['dejavusans' , 'dejavuserif' , 'cm' , 'stix' , 'stixsans' , 'custom' ],
418
+ _deprecated_since = "3.3" )
412
419
validate_mathtext_default = ValidateInStrings (
413
- 'default' , "rm cal it tt sf bf default bb frak scr regular" .split ())
414
-
415
-
420
+ 'default' , "rm cal it tt sf bf default bb frak scr regular" .split (),
421
+ _deprecated_since = "3.3" )
416
422
_validate_alignment = ValidateInStrings (
417
423
'alignment' ,
418
- ['center' , 'top' , 'bottom' , 'baseline' ,
419
- 'center_baseline' ] )
424
+ ['center' , 'top' , 'bottom' , 'baseline' , 'center_baseline' ],
425
+ _deprecated_since = "3.3" )
420
426
421
427
422
428
def validate_whiskers (s ):
@@ -635,7 +641,8 @@ def validate_markevery(s):
635
641
'upper center' ,
636
642
'center' ], ignorecase = True )
637
643
638
- validate_svg_fonttype = ValidateInStrings ('svg.fonttype' , ['none' , 'path' ])
644
+ validate_svg_fonttype = ValidateInStrings (
645
+ 'svg.fonttype' , ['none' , 'path' ], _deprecated_since = "3.3" )
639
646
640
647
641
648
def validate_hinting (s ):
@@ -650,8 +657,9 @@ def validate_hinting(s):
650
657
raise ValueError ("hinting should be 'auto', 'native', 'either' or 'none'" )
651
658
652
659
653
- validate_pgf_texsystem = ValidateInStrings ('pgf.texsystem' ,
654
- ['xelatex' , 'lualatex' , 'pdflatex' ])
660
+ validate_pgf_texsystem = ValidateInStrings (
661
+ 'pgf.texsystem' , ['xelatex' , 'lualatex' , 'pdflatex' ],
662
+ _deprecated_since = "3.3" )
655
663
656
664
657
665
def validate_movie_writer (s ):
@@ -665,12 +673,13 @@ def validate_movie_writer(s):
665
673
666
674
667
675
validate_movie_frame_fmt = ValidateInStrings ('animation.frame_format' ,
668
- ['png' , 'jpeg' , 'tiff' , 'raw' , 'rgba' ])
676
+ ['png' , 'jpeg' , 'tiff' , 'raw' , 'rgba' ], _deprecated_since = "3.3" )
669
677
670
- validate_axis_locator = ValidateInStrings ('major' , ['minor' , 'both' , 'major' ])
678
+ validate_axis_locator = ValidateInStrings (
679
+ 'major' , ['minor' , 'both' , 'major' ], _deprecated_since = "3.3" )
671
680
672
681
validate_movie_html_fmt = ValidateInStrings ('animation.html' ,
673
- ['html5' , 'jshtml' , 'none' ])
682
+ ['html5' , 'jshtml' , 'none' ], _deprecated_since = "3.3" )
674
683
675
684
676
685
def validate_bbox (s ):
@@ -723,7 +732,8 @@ def _validate_greaterequal0_lessequal1(s):
723
732
}
724
733
725
734
726
- validate_grid_axis = ValidateInStrings ('axes.grid.axis' , ['x' , 'y' , 'both' ])
735
+ validate_grid_axis = ValidateInStrings (
736
+ 'axes.grid.axis' , ['x' , 'y' , 'both' ], _deprecated_since = "3.3" )
727
737
728
738
729
739
def validate_hatch (s ):
@@ -971,15 +981,13 @@ def validate_webagg_address(s):
971
981
raise ValueError ("'webagg.address' is not a valid IP address" )
972
982
973
983
974
- validate_axes_titlelocation = ValidateInStrings ('axes.titlelocation' ,
975
- ['left' , 'center' , 'right' ])
976
- _validate_xaxis_labellocation = ValidateInStrings ('xaxis.labellocation' ,
977
- ['left' , 'center' , 'right' ])
978
- _validate_yaxis_labellocation = ValidateInStrings ('yaxis.labellocation' ,
979
- ['bottom' , 'center' , 'top' ])
984
+ validate_axes_titlelocation = ValidateInStrings (
985
+ 'axes.titlelocation' , ['left' , 'center' , 'right' ], _deprecated_since = "3.3" )
980
986
981
987
982
- # a map from key -> value, converter
988
+ # A map of key -> [value, converter].
989
+ # Converters given as lists are converted to ValidateInStrings immediately
990
+ # below.
983
991
defaultParams = {
984
992
'backend' : [_auto_backend_sentinel , validate_backend ],
985
993
'backend_fallback' : [True , validate_bool ],
@@ -1124,16 +1132,19 @@ def validate_webagg_address(s):
1124
1132
'mathtext.it' : ['sans:italic' , validate_font_properties ],
1125
1133
'mathtext.bf' : ['sans:bold' , validate_font_properties ],
1126
1134
'mathtext.sf' : ['sans' , validate_font_properties ],
1127
- 'mathtext.fontset' : ['dejavusans' , validate_fontset ],
1128
- 'mathtext.default' : ['it' , validate_mathtext_default ],
1135
+ 'mathtext.fontset' : [
1136
+ 'dejavusans' ,
1137
+ ['dejavusans' , 'dejavuserif' , 'cm' , 'stix' , 'stixsans' , 'custom' ]],
1138
+ 'mathtext.default' : [
1139
+ 'it' ,
1140
+ ['rm' , 'cal' , 'it' , 'tt' , 'sf' , 'bf' , 'default' , 'bb' , 'frak' , 'scr' , 'regular' ]],
1129
1141
'mathtext.fallback_to_cm' : [True , validate_bool ],
1130
1142
1131
1143
'image.aspect' : ['equal' , validate_aspect ], # equal, auto, a number
1132
1144
'image.interpolation' : ['antialiased' , validate_string ],
1133
1145
'image.cmap' : ['viridis' , validate_string ], # gray, jet, etc.
1134
1146
'image.lut' : [256 , validate_int ], # lookup table
1135
- 'image.origin' : ['upper' ,
1136
- ValidateInStrings ('image.origin' , ['upper' , 'lower' ])],
1147
+ 'image.origin' : ['upper' , ['upper' , 'lower' ]],
1137
1148
'image.resample' : [True , validate_bool ],
1138
1149
# Specify whether vector graphics backends will combine all images on a
1139
1150
# set of axes into a single composite image
@@ -1147,8 +1158,8 @@ def validate_webagg_address(s):
1147
1158
'errorbar.capsize' : [0 , validate_float ],
1148
1159
1149
1160
# axis props
1150
- 'xaxis.labellocation' : ['center' , _validate_xaxis_labellocation ], # alignment of x axis title
1151
- 'yaxis.labellocation' : ['center' , _validate_yaxis_labellocation ], # alignment of y axis title
1161
+ 'xaxis.labellocation' : ['center' , [ 'left' , 'center' , 'right' ] ], # alignment of x axis title
1162
+ 'yaxis.labellocation' : ['center' , [ 'bottom' , 'center' , 'top' ] ], # alignment of y axis title
1152
1163
1153
1164
# axes props
1154
1165
'axes.axisbelow' : ['line' , validate_axisbelow ],
@@ -1163,16 +1174,14 @@ def validate_webagg_address(s):
1163
1174
1164
1175
'axes.titlesize' : ['large' , validate_fontsize ], # fontsize of the
1165
1176
# axes title
1166
- 'axes.titlelocation' : ['center' , validate_axes_titlelocation ], # alignment of axes title
1177
+ 'axes.titlelocation' : ['center' , [ 'left' , 'center' , 'right' ] ], # alignment of axes title
1167
1178
'axes.titleweight' : ['normal' , validate_fontweight ], # font weight of axes title
1168
1179
'axes.titlecolor' : ['auto' , validate_color_or_auto ], # font color of axes title
1169
1180
'axes.titlepad' : [6.0 , validate_float ], # pad from axes top to title in points
1170
1181
'axes.grid' : [False , validate_bool ], # display grid or not
1171
- 'axes.grid.which' : ['major' , validate_axis_locator ], # set whether the gid are by
1172
- # default draw on 'major'
1173
- # 'minor' or 'both' kind of
1174
- # axis locator
1175
- 'axes.grid.axis' : ['both' , validate_grid_axis ], # grid type:
1182
+ 'axes.grid.which' : ['major' , ['minor' , 'both' , 'major' ]], # set whether the grid is drawn on
1183
+ # 'major' 'minor' or 'both' ticks
1184
+ 'axes.grid.axis' : ['both' , ['x' , 'y' , 'both' ]], # grid type:
1176
1185
# 'x', 'y', or 'both'
1177
1186
'axes.labelsize' : ['medium' , validate_fontsize ], # fontsize of the
1178
1187
# x any y labels
@@ -1201,9 +1210,7 @@ def validate_webagg_address(s):
1201
1210
validate_cycler ],
1202
1211
# If 'data', axes limits are set close to the data.
1203
1212
# If 'round_numbers' axes limits are set to the nearest round numbers.
1204
- 'axes.autolimit_mode' : [
1205
- 'data' ,
1206
- ValidateInStrings ('autolimit_mode' , ['data' , 'round_numbers' ])],
1213
+ 'axes.autolimit_mode' : ['data' , ['data' , 'round_numbers' ]],
1207
1214
'axes.xmargin' : [0.05 , _range_validators ["0 <= x <= 1" ]],
1208
1215
'axes.ymargin' : [0.05 , _range_validators ["0 <= x <= 1" ]],
1209
1216
@@ -1278,7 +1285,8 @@ def validate_webagg_address(s):
1278
1285
# fontsize of the xtick labels
1279
1286
'xtick.labelsize' : ['medium' , validate_fontsize ],
1280
1287
'xtick.direction' : ['out' , validate_string ], # direction of xticks
1281
- 'xtick.alignment' : ["center" , _validate_alignment ],
1288
+ 'xtick.alignment' : ['center' ,
1289
+ ['center' , 'top' , 'bottom' , 'baseline' , 'center_baseline' ]],
1282
1290
1283
1291
'ytick.left' : [True , validate_bool ], # draw ticks on the left side
1284
1292
'ytick.right' : [False , validate_bool ], # draw ticks on the right side
@@ -1300,7 +1308,8 @@ def validate_webagg_address(s):
1300
1308
# fontsize of the ytick labels
1301
1309
'ytick.labelsize' : ['medium' , validate_fontsize ],
1302
1310
'ytick.direction' : ['out' , validate_string ], # direction of yticks
1303
- 'ytick.alignment' : ["center_baseline" , _validate_alignment ],
1311
+ 'ytick.alignment' : ['center_baseline' ,
1312
+ ['center' , 'top' , 'bottom' , 'baseline' , 'center_baseline' ]],
1304
1313
1305
1314
'grid.color' : ['#b0b0b0' , validate_color ], # grid color
1306
1315
'grid.linestyle' : ['-' , _validate_linestyle ], # solid
@@ -1346,7 +1355,7 @@ def validate_webagg_address(s):
1346
1355
'savefig.dpi' : ['figure' , validate_dpi ], # DPI
1347
1356
'savefig.facecolor' : ['white' , validate_color ],
1348
1357
'savefig.edgecolor' : ['white' , validate_color ],
1349
- 'savefig.orientation' : ['portrait' , validate_orientation ],
1358
+ 'savefig.orientation' : ['portrait' , [ 'landscape' , 'portrait' ] ],
1350
1359
'savefig.jpeg_quality' : [95 , validate_int ],
1351
1360
# value checked by backend at runtime
1352
1361
'savefig.format' : ['png' , _update_savefig_format ],
@@ -1376,7 +1385,7 @@ def validate_webagg_address(s):
1376
1385
'pdf.fonttype' : [3 , validate_fonttype ], # 3 (Type3) or 42 (Truetype)
1377
1386
1378
1387
# choose latex application for creating pdf files (xelatex/lualatex)
1379
- 'pgf.texsystem' : ['xelatex' , validate_pgf_texsystem ],
1388
+ 'pgf.texsystem' : ['xelatex' , [ 'xelatex' , 'lualatex' , 'pdflatex' ] ],
1380
1389
# use matplotlib rc settings for font configuration
1381
1390
'pgf.rcfonts' : [True , validate_bool ],
1382
1391
# provide a custom preamble for the latex process
@@ -1385,7 +1394,7 @@ def validate_webagg_address(s):
1385
1394
# write raster image data directly into the svg file
1386
1395
'svg.image_inline' : [True , validate_bool ],
1387
1396
# True to save all characters as paths in the SVG
1388
- 'svg.fonttype' : ['path' , validate_svg_fonttype ],
1397
+ 'svg.fonttype' : ['path' , [ 'none' , 'path' ] ],
1389
1398
'svg.hashsalt' : [None , validate_string_or_None ],
1390
1399
1391
1400
# set this when you want to generate hardcopy docstring
@@ -1419,15 +1428,15 @@ def validate_webagg_address(s):
1419
1428
'keymap.copy' : [['ctrl+c' , 'cmd+c' ], validate_stringlist ],
1420
1429
1421
1430
# Animation settings
1422
- 'animation.html' : ['none' , validate_movie_html_fmt ],
1431
+ 'animation.html' : ['none' , [ 'html5' , 'jshtml' , 'none' ] ],
1423
1432
# Limit, in MB, of size of base64 encoded animation in HTML
1424
1433
# (i.e. IPython notebook)
1425
1434
'animation.embed_limit' : [20 , validate_float ],
1426
1435
'animation.writer' : ['ffmpeg' , validate_movie_writer ],
1427
1436
'animation.codec' : ['h264' , validate_string ],
1428
1437
'animation.bitrate' : [- 1 , validate_int ],
1429
1438
# Controls image format when frames are written to disk
1430
- 'animation.frame_format' : ['png' , validate_movie_frame_fmt ],
1439
+ 'animation.frame_format' : ['png' , [ 'png' , 'jpeg' , 'tiff' , 'raw' , 'rgba' ] ],
1431
1440
# Additional arguments for HTML writer
1432
1441
'animation.html_args' : [[], validate_stringlist ],
1433
1442
# Path to ffmpeg binary. If just binary name, subprocess uses $PATH.
@@ -1451,3 +1460,7 @@ def validate_webagg_address(s):
1451
1460
# altogether. For that use `matplotlib.style.use('classic')`.
1452
1461
'_internal.classic_mode' : [False , validate_bool ]
1453
1462
}
1463
+ defaultParams = {
1464
+ k : [default ,
1465
+ ValidateInStrings (k , conv ) if isinstance (conv , list ) else conv ]
1466
+ for k , (default , conv ) in defaultParams .items ()}
0 commit comments