Repository navigation
fix: keep the defaults a MATLAB-style format string does not set in mpl_styling - #267
Merged
Merged
Conversation
…pl_styling
The parser gave None for each part the string did not set, and that None
replaced the default, so plot_ellipse('--') lost its default color. Replace it
with parse_fmt, a copy of the function proposed for spatialmath (PR 321), which
returns only what the string sets and follows plot(): a marker with no line
style means no line. Tested against Matplotlib's own parser.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 54 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes
mpl_stylinglosing the default of anything a MATLAB-style format string does not set, and replaces its hand-written parser with one that follows Matplotlib's rules.The bug. The old parser returned
Nonefor each of color, marker and line style that the string did not set, and thatNonereplaced the default, sompl_styling("--", dict(color="red"))gave no color.blobs.plot_ellipse("--")drew in the next color of the Matplotlib cycle, not the documented cyan.The change.
parse_fmtinbase/graphics.pyreplaces the nested parser. It returns only the parts the string sets, sodefaults | parse_fmt(fmt) | kwargskeeps every default the string leaves alone. It followsplt.plot:"g""r--""r:""r.""--"It also accepts cycle colors (
"C2"), whole-string colors ("red","#ff8000"), and the markers the old regex missed (X,8,1to4). It raisesValueError("... is not a valid format string") for two colors, two markers, two line styles or an unknown character.Behavior change. A string with a marker but no line style now means markers only, as in
plot. Forplot_perimeter,plot_ellipseandplot_axes, a string such as"o"or"r."used to give the line with markers on it, and now gives the markers only. The other fiveBlobs.plot_*methods already did this, because they also hand the string to spatialmath. Strings with no marker, or with a line style, are unchanged.A copy.
parse_fmtis a copy of the function proposed for spatialmath in rai-opensource/spatialmath-python PR 321 (open), which will take months to reach a release. There is a comment at the copy to remove it and import that one once the release is the minimum we require.Tests:
tests/base/test_parse_fmt.py(copied from the spatialmath PR) comparesparse_fmtwith Matplotlib's own parser for about 6,600 valid strings in every order, every valid pair, whole-string colors and a set of invalid strings;test_mpl_styling.pyhas new tests that unset parts keep their defaults, and the old tests are updated for the new error text and for"o"giving no line. mypy reports no issues and the full suite passes (2244 passed, 33 skipped).AI-assisted: written with Claude Code (Claude Sonnet 5.5) and reviewed by the maintainer.
🤖 Generated with Claude Code