Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow numpy arrays in markevery#17276

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

ImportanceOfBeingErnest
Copy link
Member

PR Summary

This line

ifself._markevery!=every:

prevents numpy arrays to be used as input tomarkevery, 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 toset_markevery.

Also creates tests for all possible cases that markevery can take.

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@ImportanceOfBeingErnestImportanceOfBeingErnest added this to thev3.3.0 milestoneApr 30, 2020
@ImportanceOfBeingErnestImportanceOfBeingErnestforce-pushed themarkevery-numpy branch 2 times, most recently from9cc1cee tob90026fCompareApril 30, 2020 16:21
@timhoffm
Copy link
Member

test_lines/test_markevery[png]

got:
test_markevery png
expected:
test_markevery png -expected
diff:
test_markevery png -failed-diff

@ImportanceOfBeingErnestImportanceOfBeingErnestforce-pushed themarkevery-numpy branch 4 times, most recently from5091cd3 tod047d13CompareMay 2, 2020 13:31
@ImportanceOfBeingErnest
Copy link
MemberAuthor

Wow, this was hard - because the tests ran perfectly fine locally. Turns out I stepped directly intonumpy/numpy#16023 (np.array(["0"]).astype(bool) isFalse in all but the very recent numpy 1.18.3).

t = np.linspace(0, 3, 14)
y = np.random.rand(len(t))

casesA = [None, 4, (2, 5), [1, 5, 11],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Optional: There is no gain from random numbers here. You could just usey = t**2 or any other simple function.

@efiring
Copy link
Member

@timhoffm's suggested test changes look easy and worthwhile so I'm holding off on a review, but otherwise this looks good.

Copy link
Member

@tacaswelltacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I agree with@timhoffm that grouping the cases the other way would be clearer, but I am not going to hold up merging over it.

Copy link
Member

@efiringefiring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Let's get this in now.@timhoffm, if you would like to put in a simple subsequent PR to improve the tests, I'm sure that can also go in quickly.

@efiringefiring merged commite7d498c intomatplotlib:masterJun 3, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic left review comments

@timhoffmtimhoffmtimhoffm left review comments

@efiringefiringefiring approved these changes

@tacaswelltacaswelltacaswell approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.3.0
Development

Successfully merging this pull request may close these issues.

5 participants
@ImportanceOfBeingErnest@timhoffm@efiring@tacaswell@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp