Repository navigation
fix: accept the short Matplotlib option names (lw, c, ...) in mpl_styling - #266
Merged
Merged
Conversation
…ling mpl_styling merged its defaults and the caller's options by key, so a caller's lw=4 sat beside the default linewidth=2 and Matplotlib refused both. Add an artist argument (Line2D, Patch, Text, ...): when given, the options are first converted to the full names for that class. The Blobs plot methods now pass it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 14 |
| 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
blobs.plot_axes(lw=4)and the same call on the otherBlobs.plot_*methods, which raised Matplotlib's "Got both 'linewidth' and 'lw', which are aliases of one another".mpl_stylingmerges the defaults and the caller's options by key name. EveryBlobs.plot_*default isdict(color=..., linewidth=2), so a caller'slw=4orc="blue"sat beside the defaultlinewidthorcolor, and Matplotlib refused the pair.artistargument.mpl_styling(fmt, defaults, kwargs, artist=Line2D)takes the Matplotlib class that will receive the options (Line2D,Patch,Text, ...). When it is given,defaultsandkwargsare first converted to the full option names withmatplotlib.cbook.normalize_kwargs, solw=4replaces the defaultlinewidth=2. When it isNone(the default) nothing changes, so existing callers are unaffected. A caller who gives both names (lw=1, linewidth=2) still gets Matplotlib's error.mpl_stylingcalls inImageBlobs.pynow passLine2D(plot_perimeter,plot_ellipse,plot_axes,plot_aligned_box,plot_MEC,plot_MER) orPatch(plot_box,plot_labelbox). The helpers for the ellipse, circle and polygon draw aLine2D, or a filledPolygonpatch whenfilled=True; both accept the full namesLine2Dconverts to.Tests (13 new, 4 of them in
tests/base/):lw,c,ls,msforLine2D,ecandfcforPatch,haandsizeforText; an alias in the defaults; an alias beating the format string; the merged options accepted by a realplotcall; the both-names error; no conversion withoutartist;Nonevalues dropped; andplot_axes,plot_ellipse,plot_perimeterandplot_boxcalled withlwandcorec. mypy reports no issues and the full suite passes (2198 passed, 33 skipped).Found while testing, not changed here: when a format string is given, the parts it does not set come back as
Noneand override the matching default, sompl_styling("--", dict(color="red"))loses the red. That will be a separatebug/PR.AI-assisted: written with Claude Code (Claude Sonnet 5.5) and reviewed by the maintainer.
🤖 Generated with Claude Code