Thanks to visit codestin.com
Credit goes to github.com

Skip to content

update set_drawstyle #10340

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 29, 2018
Merged

Conversation

ImportanceOfBeingErnest
Copy link
Member

@ImportanceOfBeingErnest ImportanceOfBeingErnest commented Jan 28, 2018

Invalidate path on set_drawstyle to recache path, such that the new drawstyle is actually applied.
Fixes #10338

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 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

Invalidate path on set_drawstyle to recache path, such that the new drawstyle is actually applied.
Fixes matplotlib#10338
@jklymak
Copy link
Member

jklymak commented Jan 28, 2018

This works for me. Can you add a test? https://matplotlib.org/devel/testing.html I guess this needs an image test, but can you remember to set style='mpl20', remove_text=True in the @image_comparparison parameters?

@ImportanceOfBeingErnest
Copy link
Member Author

ImportanceOfBeingErnest commented Jan 28, 2018

I guess a test could look like this, just checking if the path has indeed been updated.

def test_set_drawstyle():
    import numpy as np
    import matplotlib.pyplot as plt
    x = np.linspace(0, 2*np.pi, 10)
    y = np.sin(x)

    fig, ax = plt.subplots() 
    line, = ax.plot(x, y)
    line.set_drawstyle("steps-pre") 
    assert len(line.get_path().vertices) == 2*len(x)-1
    line.set_drawstyle("default")
    assert len(line.get_path().vertices) == len(x)

Where exactly would I add this test? I can't find a matplotlib/test directory on my fork.

@jklymak
Copy link
Member

jklymak commented Jan 28, 2018

lib/matplotlib/tests. Probably in test_lines.py?

Add a test for setting drawstyle after line creation
@ImportanceOfBeingErnest
Copy link
Member Author

Ok, found it. Thanks.

assert len(line.get_path().vertices) == 2*len(x)-1

line.set_drawstyle("default")
assert len(line.get_path().vertices) == len(x)

Copy link
Member

Choose a reason for hiding this comment

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

PEP8 will complain you need an extra line here (and maybe some other things above - I'm terrible at PEP8. But once this passes it looks good to me. Thanks!

Add a test for setting drawstyle after line creation, remove whitespaces to satisfy the PEP gods.
@jklymak jklymak requested a review from anntzer January 29, 2018 04:57
@jklymak jklymak added this to the v2.2 milestone Jan 29, 2018
@jklymak
Copy link
Member

jklymak commented Jan 29, 2018

This isn't really urgent for 2.2, but is small enough that it should be quick to review

@anntzer
Copy link
Contributor

anntzer commented Jan 29, 2018

was going to abstain given that I basiclaly posted the patch, but I guess @ImportanceOfBeingErnest also likes it so...

@anntzer anntzer merged commit 6839a6d into matplotlib:master Jan 29, 2018
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
@ImportanceOfBeingErnest ImportanceOfBeingErnest deleted the patch-7 branch May 10, 2018 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

line.set_drawstyle fails to produce step-like line
4 participants