FIX: avoid applying dashed patterns to zero-width lines and patches#31307
FIX: avoid applying dashed patterns to zero-width lines and patches#31307ksunden merged 4 commits intomatplotlib:mainfrom
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. You can also join us on gitter for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
timhoffm
left a comment
There was a problem hiding this comment.
I think coping with this at draw time is the right approach.
Tests could be a bit more expressive. They are currently only smoke tests, i.e. ensure they don't blow up, but don't test the result.
You may be able to use https://matplotlib.org/stable/api/testing_api.html#matplotlib.testing.decorators.check_figures_equal.
For example in the stairs case, you could draw once with ls='-' and once with ls=--`. The claim would be that both are identical because for a zero linewidth, the linestyle does not matter.
|
I updated the regressions to use |
|
This is what I did to get through testing the other PR (albeit in a simpler form), so I do think it's the right approach. However, if I revert the |
|
I believe you need the |
|
I updated the tests accordingly. |
| autospec=True, | ||
| wraps=matplotlib.backend_bases.GraphicsContextBase.set_dashes, | ||
| ) as set_dashes: | ||
| line.draw(renderer) |
There was a problem hiding this comment.
You should use fig.draw_without_rendering() instead of reaching in to the internals.
|
I simplified the generic |
PR summary
closes #31302
This fixes a draw-time failure for zero-width dashed strokes.
Minimum reproduction:
Before this change, this produced lw=0.0 and _dash_pattern=(0.0, [0.0, 0.0]), then raised ValueError: At least one value in the dash list must be positive.
This patch fixes the issue at draw time by avoiding application of dash patterns when the effective linewidth is zero. That keeps the public artist state unchanged while preventing invalid all-zero dash patterns from being passed to
the graphics context. In particular, this avoids changing stored linestyle state or getter behavior, which keeps the fix narrowly scoped to rendering.
Regression tests are added for zero-width dashed Line2D, filled stairs under mpl20, and zero-width dashed Patch.
AI Disclosure
I used AI as a debugging aid while investigating the failure and drafting candidate regression tests. I reviewed the resulting changes, reproduced the failure locally before the fix, and ran the added tests locally after the fix.
PR checklist