Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bee936

Browse files
committed
Added markevery validator to rcparams with basic rcparams test
1 parent ef5d01a commit 3bee936

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

lib/matplotlib/rcsetup.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,36 @@ def validate_ps_distiller(s):
534534
_validate_negative_linestyle = ValidateInStrings('negative_linestyle',
535535
['solid', 'dashed'],
536536
ignorecase=True)
537+
def validate_markevery(s):
538+
"""
539+
Validate the markevery property of a Line2D object.
540+
541+
Parameters
542+
----------
543+
s : None, int, float, slice, length-2 tuple of ints,
544+
length-2 tuple of floats, list
545+
546+
Returns
547+
-------
548+
s : None, int, float, slice, length-2 tuple of ints,
549+
length-2 tuple of floats, list, ValueError
550+
551+
"""
552+
553+
if isinstance(s, tuple):
554+
# Ensure correct length of 2
555+
if len(s) != 2:
556+
raise ValueError("'markevery' tuple must be a length of 2")
557+
# Ensure that all elements in the tuple are of type int
558+
if not all(isinstance(x, int) for x in s):
559+
raise ValueError("'markevery' tuple ")
560+
# Ensure that all elements in the tuple are of type float
561+
elif not all(isinstance(x, float) for x in s):
562+
raise ValueError("'markevery' tuple ")
563+
564+
return s;
537565

566+
validate_markeverylist = _listify_validator(validate_markevery)
538567

539568
validate_legend_loc = ValidateInStrings(
540569
'legend_loc',
@@ -676,6 +705,7 @@ def validate_hatch(s):
676705
'markersize': validate_floatlist,
677706
'markeredgewidth': validate_floatlist,
678707
'markeredgecolor': validate_colorlist,
708+
'markevery': validate_markeverylist,
679709
'alpha': validate_floatlist,
680710
'marker': validate_stringlist,
681711
'hatch': validate_hatchlist,

lib/matplotlib/tests/test_rcparams.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
validate_cycler,
2424
validate_hatch,
2525
validate_hist_bins,
26+
validate_markevery,
2627
_validate_linestyle)
2728

2829

@@ -326,6 +327,17 @@ def generate_validator_testcases(valid):
326327
),
327328
'fail': (('aardvark', ValueError),
328329
)
330+
},
331+
{'validator': validate_markevery,
332+
'success': ((None,None),
333+
(1,1),
334+
(0.1,0.1)
335+
),
336+
'fail': (((1,2,3), ValueError),
337+
((0.1,0.2,0.3), ValueError),
338+
((1,0.1), ValueError),
339+
(('abc'), ValueError)
340+
)
329341
}
330342
)
331343

0 commit comments

Comments
 (0)