-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: Stricter validation of line style rcParams (and extended accepted types for grid.linestyle
)
#8040
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
Merged
NelleV
merged 15 commits into
matplotlib:master
from
afvincent:wip_relax_grid_ls_validation
Feb 18, 2017
Merged
ENH: Stricter validation of line style rcParams (and extended accepted types for grid.linestyle
)
#8040
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
061061b
extend 'grid.linestyle' valid types to on-off ink sequences
afvincent 5be29b5
extend 'add test for the new function 'validate_grid_linestyle'
afvincent 25efd07
fix a small typo
afvincent 5cb183c
Relax validation for all ls-related rcParams but contour.negative_lin…
afvincent d9ff6a8
Check that strings are valid line styles
afvincent 44c3fde
fix PEP8
afvincent e8032df
use validate_linestyle even for rcParam 'contour.negative_linestyle'
afvincent 2673585
Reintroduce former public validators for negative contours (but they …
afvincent 7bd9bfe
make validate_linestyle private and case insensitive (+ adapt relevan…
afvincent ad21964
Remove deprecation warning in 'validate_negative_linestyle_legacy'
afvincent 7ab75f5
Deprecate former validation schemes used by 'contour.negative_linestyle'
afvincent 59328e6
Fix typo (a forgotten 'return' statement...)
afvincent 70e87c8
Fix the deprecation decorators
afvincent c060842
Add a what's new entry
afvincent aabf385
Fix a typo with the example in the what's new entry
afvincent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
import warnings | ||
import re | ||
|
||
from matplotlib.cbook import mplDeprecation | ||
from matplotlib.cbook import mplDeprecation, ls_mapper | ||
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern | ||
from matplotlib.colors import is_color_like | ||
|
||
|
@@ -530,22 +530,6 @@ def validate_ps_distiller(s): | |
'top', 'none']) | ||
validate_fillstylelist = _listify_validator(validate_fillstyle) | ||
|
||
validate_negative_linestyle = ValidateInStrings('negative_linestyle', | ||
['solid', 'dashed'], | ||
ignorecase=True) | ||
|
||
|
||
def validate_negative_linestyle_legacy(s): | ||
try: | ||
res = validate_negative_linestyle(s) | ||
return res | ||
except ValueError: | ||
dashes = validate_nseq_float(2)(s) | ||
warnings.warn("Deprecated negative_linestyle specification; use " | ||
"'solid' or 'dashed'", | ||
mplDeprecation) | ||
return (0, dashes) # (offset, (solid, blank)) | ||
|
||
|
||
def validate_corner_mask(s): | ||
if s == 'legacy': | ||
|
@@ -888,6 +872,36 @@ def validate_animation_writer_path(p): | |
modules["matplotlib.animation"].writers.set_dirty() | ||
return p | ||
|
||
# A validator dedicated to the named line styles, based on the items in | ||
# ls_mapper, and a list of possible strings read from Line2D.set_linestyle | ||
validate_named_linestyle = ValidateInStrings('linestyle', | ||
list(six.iterkeys(ls_mapper)) + | ||
list(six.itervalues(ls_mapper)) + | ||
['None', 'none', ' ', ''], | ||
ignorecase=False) | ||
|
||
# A validator for all possible line styles, the named ones *and* | ||
# the on-off ink sequences. | ||
def validate_linestyle(ls): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make this a private function? I don't think it should be added to our public API. |
||
# Named line style, like u'--' or u'solid' | ||
if isinstance(ls, six.text_type): | ||
return validate_named_linestyle(ls) | ||
|
||
# On-off ink (in points) sequence *of even length*. | ||
# Offset is set to None. | ||
try: | ||
if len(ls) % 2 != 0: | ||
# Expecting a sequence of even length | ||
raise ValueError | ||
return (None, validate_nseq_float()(ls)) | ||
except (ValueError, TypeError): | ||
# TypeError can be raised by wrong types passed to float() | ||
# (called inside the instance of validate_nseq_float). | ||
pass | ||
|
||
raise ValueError("linestyle must be a string or " + | ||
"an even-length sequence of floats.") | ||
|
||
|
||
# a map from key -> value, converter | ||
defaultParams = { | ||
|
@@ -912,7 +926,7 @@ def validate_animation_writer_path(p): | |
|
||
# line props | ||
'lines.linewidth': [1.5, validate_float], # line width in points | ||
'lines.linestyle': ['-', six.text_type], # solid line | ||
'lines.linestyle': ['-', validate_linestyle], # solid line | ||
'lines.color': ['C0', validate_color], # first color in color cycle | ||
'lines.marker': ['None', six.text_type], # marker name | ||
'lines.markeredgewidth': [1.0, validate_float], | ||
|
@@ -961,31 +975,31 @@ def validate_animation_writer_path(p): | |
'boxplot.flierprops.markerfacecolor': ['none', validate_color_or_auto], | ||
'boxplot.flierprops.markeredgecolor': ['k', validate_color], | ||
'boxplot.flierprops.markersize': [6, validate_float], | ||
'boxplot.flierprops.linestyle': ['none', six.text_type], | ||
'boxplot.flierprops.linestyle': ['none', validate_linestyle], | ||
'boxplot.flierprops.linewidth': [1.0, validate_float], | ||
|
||
'boxplot.boxprops.color': ['k', validate_color], | ||
'boxplot.boxprops.linewidth': [1.0, validate_float], | ||
'boxplot.boxprops.linestyle': ['-', six.text_type], | ||
'boxplot.boxprops.linestyle': ['-', validate_linestyle], | ||
|
||
'boxplot.whiskerprops.color': ['k', validate_color], | ||
'boxplot.whiskerprops.linewidth': [1.0, validate_float], | ||
'boxplot.whiskerprops.linestyle': ['-', six.text_type], | ||
'boxplot.whiskerprops.linestyle': ['-', validate_linestyle], | ||
|
||
'boxplot.capprops.color': ['k', validate_color], | ||
'boxplot.capprops.linewidth': [1.0, validate_float], | ||
'boxplot.capprops.linestyle': ['-', six.text_type], | ||
'boxplot.capprops.linestyle': ['-', validate_linestyle], | ||
|
||
'boxplot.medianprops.color': ['C1', validate_color], | ||
'boxplot.medianprops.linewidth': [1.0, validate_float], | ||
'boxplot.medianprops.linestyle': ['-', six.text_type], | ||
'boxplot.medianprops.linestyle': ['-', validate_linestyle], | ||
|
||
'boxplot.meanprops.color': ['C2', validate_color], | ||
'boxplot.meanprops.marker': ['^', six.text_type], | ||
'boxplot.meanprops.markerfacecolor': ['C2', validate_color], | ||
'boxplot.meanprops.markeredgecolor': ['C2', validate_color], | ||
'boxplot.meanprops.markersize': [6, validate_float], | ||
'boxplot.meanprops.linestyle': ['--', six.text_type], | ||
'boxplot.meanprops.linestyle': ['--', validate_linestyle], | ||
'boxplot.meanprops.linewidth': [1.0, validate_float], | ||
|
||
## font props | ||
|
@@ -1051,8 +1065,7 @@ def validate_animation_writer_path(p): | |
'image.composite_image': [True, validate_bool], | ||
|
||
# contour props | ||
'contour.negative_linestyle': ['dashed', | ||
validate_negative_linestyle_legacy], | ||
'contour.negative_linestyle': ['dashed', validate_linestyle], | ||
'contour.corner_mask': [True, validate_corner_mask], | ||
|
||
# errorbar props | ||
|
@@ -1215,7 +1228,7 @@ def validate_animation_writer_path(p): | |
'ytick.direction': ['out', six.text_type], # direction of yticks | ||
|
||
'grid.color': ['#b0b0b0', validate_color], # grid color | ||
'grid.linestyle': ['-', six.text_type], # solid | ||
'grid.linestyle': ['-', validate_linestyle], # solid | ||
'grid.linewidth': [0.8, validate_float], # in points | ||
'grid.alpha': [1.0, validate_float], | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. this should not appear in our public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'll do that! (I was hesitating because most of the other validators are public).
Speaking of public API, I think I've done something wrong (:sheep:) by genuinely getting rid off of
validate_negative_linestyle
andvalidate_negative_linestyle_legacy
as they were both part of the public API. I should have used some deprecation warning instead, shouldn't I? Or at least just leave them (because ifvalidate_linestyle
is made private, there will be no alternative)?