25
25
import warnings
26
26
import re
27
27
28
- from matplotlib .cbook import mplDeprecation
28
+ from matplotlib .cbook import mplDeprecation , deprecated , ls_mapper
29
29
from matplotlib .fontconfig_pattern import parse_fontconfig_pattern
30
30
from matplotlib .colors import is_color_like
31
31
@@ -530,20 +530,28 @@ def validate_ps_distiller(s):
530
530
'top' , 'none' ])
531
531
validate_fillstylelist = _listify_validator (validate_fillstyle )
532
532
533
- validate_negative_linestyle = ValidateInStrings ('negative_linestyle' ,
534
- ['solid' , 'dashed' ],
535
- ignorecase = True )
533
+ _validate_negative_linestyle = ValidateInStrings ('negative_linestyle' ,
534
+ ['solid' , 'dashed' ],
535
+ ignorecase = True )
536
536
537
537
538
+ @deprecated ('2.1' ,
539
+ addendum = (" See 'validate_negative_linestyle_legacy' " +
540
+ "deprecation warning for more information." ))
541
+ def validate_negative_linestyle (s ):
542
+ return _validate_negative_linestyle (s )
543
+
544
+
545
+ @deprecated ('2.1' ,
546
+ addendum = (" The 'contour.negative_linestyle' rcParam now " +
547
+ "follows the same validation as the other rcParams " +
548
+ "that are related to line style." ))
538
549
def validate_negative_linestyle_legacy (s ):
539
550
try :
540
551
res = validate_negative_linestyle (s )
541
552
return res
542
553
except ValueError :
543
554
dashes = validate_nseq_float (2 )(s )
544
- warnings .warn ("Deprecated negative_linestyle specification; use "
545
- "'solid' or 'dashed'" ,
546
- mplDeprecation )
547
555
return (0 , dashes ) # (offset, (solid, blank))
548
556
549
557
@@ -888,6 +896,39 @@ def validate_animation_writer_path(p):
888
896
modules ["matplotlib.animation" ].writers .set_dirty ()
889
897
return p
890
898
899
+ # A validator dedicated to the named line styles, based on the items in
900
+ # ls_mapper, and a list of possible strings read from Line2D.set_linestyle
901
+ _validate_named_linestyle = ValidateInStrings ('linestyle' ,
902
+ list (six .iterkeys (ls_mapper )) +
903
+ list (six .itervalues (ls_mapper )) +
904
+ ['None' , 'none' , ' ' , '' ],
905
+ ignorecase = True )
906
+
907
+
908
+ def _validate_linestyle (ls ):
909
+ """
910
+ A validator for all possible line styles, the named ones *and*
911
+ the on-off ink sequences.
912
+ """
913
+ # Named line style, like u'--' or u'solid'
914
+ if isinstance (ls , six .text_type ):
915
+ return _validate_named_linestyle (ls )
916
+
917
+ # On-off ink (in points) sequence *of even length*.
918
+ # Offset is set to None.
919
+ try :
920
+ if len (ls ) % 2 != 0 :
921
+ # Expecting a sequence of even length
922
+ raise ValueError
923
+ return (None , validate_nseq_float ()(ls ))
924
+ except (ValueError , TypeError ):
925
+ # TypeError can be raised by wrong types passed to float()
926
+ # (called inside the instance of validate_nseq_float).
927
+ pass
928
+
929
+ raise ValueError ("linestyle must be a string or " +
930
+ "an even-length sequence of floats." )
931
+
891
932
892
933
# a map from key -> value, converter
893
934
defaultParams = {
@@ -912,7 +953,7 @@ def validate_animation_writer_path(p):
912
953
913
954
# line props
914
955
'lines.linewidth' : [1.5 , validate_float ], # line width in points
915
- 'lines.linestyle' : ['-' , six . text_type ], # solid line
956
+ 'lines.linestyle' : ['-' , _validate_linestyle ], # solid line
916
957
'lines.color' : ['C0' , validate_color ], # first color in color cycle
917
958
'lines.marker' : ['None' , six .text_type ], # marker name
918
959
'lines.markeredgewidth' : [1.0 , validate_float ],
@@ -961,31 +1002,31 @@ def validate_animation_writer_path(p):
961
1002
'boxplot.flierprops.markerfacecolor' : ['none' , validate_color_or_auto ],
962
1003
'boxplot.flierprops.markeredgecolor' : ['k' , validate_color ],
963
1004
'boxplot.flierprops.markersize' : [6 , validate_float ],
964
- 'boxplot.flierprops.linestyle' : ['none' , six . text_type ],
1005
+ 'boxplot.flierprops.linestyle' : ['none' , _validate_linestyle ],
965
1006
'boxplot.flierprops.linewidth' : [1.0 , validate_float ],
966
1007
967
1008
'boxplot.boxprops.color' : ['k' , validate_color ],
968
1009
'boxplot.boxprops.linewidth' : [1.0 , validate_float ],
969
- 'boxplot.boxprops.linestyle' : ['-' , six . text_type ],
1010
+ 'boxplot.boxprops.linestyle' : ['-' , _validate_linestyle ],
970
1011
971
1012
'boxplot.whiskerprops.color' : ['k' , validate_color ],
972
1013
'boxplot.whiskerprops.linewidth' : [1.0 , validate_float ],
973
- 'boxplot.whiskerprops.linestyle' : ['-' , six . text_type ],
1014
+ 'boxplot.whiskerprops.linestyle' : ['-' , _validate_linestyle ],
974
1015
975
1016
'boxplot.capprops.color' : ['k' , validate_color ],
976
1017
'boxplot.capprops.linewidth' : [1.0 , validate_float ],
977
- 'boxplot.capprops.linestyle' : ['-' , six . text_type ],
1018
+ 'boxplot.capprops.linestyle' : ['-' , _validate_linestyle ],
978
1019
979
1020
'boxplot.medianprops.color' : ['C1' , validate_color ],
980
1021
'boxplot.medianprops.linewidth' : [1.0 , validate_float ],
981
- 'boxplot.medianprops.linestyle' : ['-' , six . text_type ],
1022
+ 'boxplot.medianprops.linestyle' : ['-' , _validate_linestyle ],
982
1023
983
1024
'boxplot.meanprops.color' : ['C2' , validate_color ],
984
1025
'boxplot.meanprops.marker' : ['^' , six .text_type ],
985
1026
'boxplot.meanprops.markerfacecolor' : ['C2' , validate_color ],
986
1027
'boxplot.meanprops.markeredgecolor' : ['C2' , validate_color ],
987
1028
'boxplot.meanprops.markersize' : [6 , validate_float ],
988
- 'boxplot.meanprops.linestyle' : ['--' , six . text_type ],
1029
+ 'boxplot.meanprops.linestyle' : ['--' , _validate_linestyle ],
989
1030
'boxplot.meanprops.linewidth' : [1.0 , validate_float ],
990
1031
991
1032
## font props
@@ -1051,8 +1092,7 @@ def validate_animation_writer_path(p):
1051
1092
'image.composite_image' : [True , validate_bool ],
1052
1093
1053
1094
# contour props
1054
- 'contour.negative_linestyle' : ['dashed' ,
1055
- validate_negative_linestyle_legacy ],
1095
+ 'contour.negative_linestyle' : ['dashed' , _validate_linestyle ],
1056
1096
'contour.corner_mask' : [True , validate_corner_mask ],
1057
1097
1058
1098
# errorbar props
@@ -1215,7 +1255,7 @@ def validate_animation_writer_path(p):
1215
1255
'ytick.direction' : ['out' , six .text_type ], # direction of yticks
1216
1256
1217
1257
'grid.color' : ['#b0b0b0' , validate_color ], # grid color
1218
- 'grid.linestyle' : ['-' , six . text_type ], # solid
1258
+ 'grid.linestyle' : ['-' , _validate_linestyle ], # solid
1219
1259
'grid.linewidth' : [0.8 , validate_float ], # in points
1220
1260
'grid.alpha' : [1.0 , validate_float ],
1221
1261
0 commit comments