|
15 | 15 | """
|
16 | 16 | import six
|
17 | 17 |
|
| 18 | +import ast |
18 | 19 | from collections import Iterable, Mapping
|
19 | 20 | from functools import reduce
|
20 | 21 | import operator
|
21 | 22 | import os
|
22 |
| -import warnings |
23 | 23 | import re
|
| 24 | +import warnings |
24 | 25 |
|
25 | 26 | from matplotlib import cbook
|
26 |
| -from matplotlib.cbook import mplDeprecation, deprecated, ls_mapper |
27 |
| -from matplotlib.fontconfig_pattern import parse_fontconfig_pattern |
28 | 27 | from matplotlib.colors import is_color_like
|
| 28 | +from matplotlib.fontconfig_pattern import parse_fontconfig_pattern |
29 | 29 |
|
30 | 30 | # Don't let the original cycler collide with our validating cycler
|
31 | 31 | from cycler import Cycler, cycler as ccycler
|
@@ -926,7 +926,8 @@ def validate_webagg_address(s):
|
926 | 926 | # ls_mapper, and a list of possible strings read from Line2D.set_linestyle
|
927 | 927 | _validate_named_linestyle = ValidateInStrings(
|
928 | 928 | 'linestyle',
|
929 |
| - [*ls_mapper.keys(), *ls_mapper.values(), 'None', 'none', ' ', ''], |
| 929 | + [*cbook.ls_mapper.keys(), *cbook.ls_mapper.values(), |
| 930 | + 'None', 'none', ' ', ''], |
930 | 931 | ignorecase=True)
|
931 | 932 |
|
932 | 933 |
|
@@ -971,6 +972,44 @@ def _validate_linestyle(ls):
|
971 | 972 | "sequence.".format(ls))
|
972 | 973 |
|
973 | 974 |
|
| 975 | +def _validate_subplot(s): |
| 976 | + d = ast.literal_eval(s) if isinstance(s, str) else s |
| 977 | + try: |
| 978 | + # These imports must be delayed because they are not available at |
| 979 | + # startup (so we just assume that the default we provide ourselves are |
| 980 | + # valid). |
| 981 | + from matplotlib import rcParams |
| 982 | + from matplotlib.figure import SubplotParams |
| 983 | + except ImportError: |
| 984 | + pass |
| 985 | + else: |
| 986 | + d = {**rcParams["figure.subplot"], **d} |
| 987 | + SubplotParams(**d) |
| 988 | + for key, value in d.items(): |
| 989 | + dict.__setitem__(rcParams, "figure.subplot.{}".format(key), value) |
| 990 | + return d |
| 991 | + |
| 992 | + |
| 993 | +def _validate_subplot_key(key): |
| 994 | + def validator(s): |
| 995 | + val = ast.literal_eval(s) if isinstance(s, str) else s |
| 996 | + try: |
| 997 | + # See above re: delayed imports. |
| 998 | + from matplotlib import rcParams |
| 999 | + from matplotlib.figure import SubplotParams |
| 1000 | + except ImportError: |
| 1001 | + pass |
| 1002 | + else: |
| 1003 | + cbook.warn_deprecated( |
| 1004 | + "3.0", "figure.subplot.{} is deprecated; set the " |
| 1005 | + "corresponding key in figure.subplot instead.".format(key)) |
| 1006 | + d = {**rcParams["figure.subplot"], key: val} |
| 1007 | + SubplotParams(**d) |
| 1008 | + dict.__setitem__(rcParams, "figure.subplot", d) |
| 1009 | + return val |
| 1010 | + return validator |
| 1011 | + |
| 1012 | + |
974 | 1013 | # a map from key -> value, converter
|
975 | 1014 | defaultParams = {
|
976 | 1015 | 'backend': ['Agg', validate_backend], # agg is certainly
|
@@ -1317,18 +1356,16 @@ def _validate_linestyle(ls):
|
1317 | 1356 | 'figure.autolayout': [False, validate_bool],
|
1318 | 1357 | 'figure.max_open_warning': [20, validate_int],
|
1319 | 1358 |
|
1320 |
| - 'figure.subplot.left': [0.125, ValidateInterval(0, 1, closedmin=True, |
1321 |
| - closedmax=True)], |
1322 |
| - 'figure.subplot.right': [0.9, ValidateInterval(0, 1, closedmin=True, |
1323 |
| - closedmax=True)], |
1324 |
| - 'figure.subplot.bottom': [0.11, ValidateInterval(0, 1, closedmin=True, |
1325 |
| - closedmax=True)], |
1326 |
| - 'figure.subplot.top': [0.88, ValidateInterval(0, 1, closedmin=True, |
1327 |
| - closedmax=True)], |
1328 |
| - 'figure.subplot.wspace': [0.2, ValidateInterval(0, 1, closedmin=True, |
1329 |
| - closedmax=False)], |
1330 |
| - 'figure.subplot.hspace': [0.2, ValidateInterval(0, 1, closedmin=True, |
1331 |
| - closedmax=False)], |
| 1359 | + 'figure.subplot': [{'left': 0.125, 'right': 0.9, |
| 1360 | + 'bottom': 0.11, 'top': 0.88, |
| 1361 | + 'wspace': 0.2, 'hspace': 0.2}, |
| 1362 | + _validate_subplot], |
| 1363 | + 'figure.subplot.left': [0.125, _validate_subplot_key('left')], |
| 1364 | + 'figure.subplot.right': [0.9, _validate_subplot_key('right')], |
| 1365 | + 'figure.subplot.bottom': [0.11, _validate_subplot_key('bottom')], |
| 1366 | + 'figure.subplot.top': [0.88, _validate_subplot_key('top')], |
| 1367 | + 'figure.subplot.wspace': [0.2, _validate_subplot_key('wspace')], |
| 1368 | + 'figure.subplot.hspace': [0.2, _validate_subplot_key('hspace')], |
1332 | 1369 |
|
1333 | 1370 | # do constrained_layout.
|
1334 | 1371 | 'figure.constrained_layout.use': [False, validate_bool],
|
|
0 commit comments