Allow numpy arrays in markevery#17276
Merged
efiring merged 1 commit intomatplotlib:masterfrom Jun 3, 2020
Merged
Conversation
9cc1cee to
b90026f
Compare
timhoffm
reviewed
May 1, 2020
b90026f to
808f7f4
Compare
Member
5091cd3 to
d047d13
Compare
d047d13 to
b73d805
Compare
Member
Author
|
Wow, this was hard - because the tests ran perfectly fine locally. Turns out I stepped directly into numpy/numpy#16023 ( |
timhoffm
reviewed
May 2, 2020
| t = np.linspace(0, 3, 14) | ||
| y = np.random.rand(len(t)) | ||
|
|
||
| casesA = [None, 4, (2, 5), [1, 5, 11], |
Member
There was a problem hiding this comment.
I think this would be more readable:
cases = [
(None, "11111111111111"),
(4, "10001000100010"),
...
]
for ax_test, ax_ref, (markevery, pattern) in zip(axs_test, axs_ref, cases):
ax_test.plot(t, y, "-gD", markevery=markevery)
ax_ref.plot(t, y, "-gD",
markevery=np.array(list(pattern)).astype(int).astype(bool))
| def test_markevery(fig_test, fig_ref): | ||
| np.random.seed(42) | ||
| t = np.linspace(0, 3, 14) | ||
| y = np.random.rand(len(t)) |
Member
There was a problem hiding this comment.
Optional: There is no gain from random numbers here. You could just use y = t**2 or any other simple function.
Member
|
@timhoffm's suggested test changes look easy and worthwhile so I'm holding off on a review, but otherwise this looks good. |
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.



PR Summary
This line
matplotlib/lib/matplotlib/lines.py
Line 583 in 9a9c8b8
prevents numpy arrays to be used as input to
markevery, BecauseThe truth value of an array with more than one element is ambiguous.That's actually a regression that came in via #4091.
I think we would like to support numpy arrays wherever possible. So this PR just removes the check and sets the artist stale on every call to
set_markevery.Also creates tests for all possible cases that markevery can take.
PR Checklist