Skip to content

Fixes #8141 #8195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ def validate_maskedarray(v):


class validate_nseq_float(object):
def __init__(self, n=None):
self.n = n
def __init__(self, n=None, allow_none=False):
self.n, self.allow_none = n, allow_none

def __call__(self, s):
"""return a seq of n floats or raise"""
Expand All @@ -309,7 +309,11 @@ def __call__(self, s):
raise ValueError(err_msg.format(n=self.n, num=len(s), s=s))

try:
return [float(val) for val in s]
return [float(val)
if self.allow_none and val is not None
or not self.allow_none
else val
for val in s]
except ValueError:
raise ValueError('Could not convert all entries to floats')

Expand Down Expand Up @@ -697,7 +701,7 @@ def validate_hatch(s):
raise ValueError("Unknown hatch symbol(s): %s" % list(unknown))
return s
validate_hatchlist = _listify_validator(validate_hatch)
validate_dashlist = _listify_validator(validate_nseq_float())
validate_dashlist = _listify_validator(validate_nseq_float(allow_none=True))

_prop_validators = {
'color': _listify_validator(validate_color_for_prop_cycle,
Expand Down Expand Up @@ -929,7 +933,6 @@ def _validate_linestyle(ls):
raise ValueError("linestyle must be a string or " +
"an even-length sequence of floats.")


# a map from key -> value, converter
defaultParams = {
'backend': ['Agg', validate_backend], # agg is certainly
Expand Down Expand Up @@ -964,7 +967,8 @@ def _validate_linestyle(ls):
'lines.dash_capstyle': ['butt', validate_capstyle],
'lines.solid_capstyle': ['projecting', validate_capstyle],
'lines.dashed_pattern': [[3.7, 1.6], validate_nseq_float()],
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6], validate_nseq_float()],
'lines.dashdot_pattern': [[6.4, 1.6, 1, 1.6],
validate_nseq_float()],
'lines.dotted_pattern': [[1, 1.65], validate_nseq_float()],
'lines.scale_dashes': [True, validate_bool],

Expand Down