Skip to content

DOCS: update collections.py docstrings to current doc conventions #17575

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 2 commits into from
Jun 10, 2020

Conversation

brunobeltran
Copy link
Contributor

@brunobeltran brunobeltran commented Jun 5, 2020

PR Summary

Meant to just add the appropriate :rc: links to the collections.py docs, but then realized that the docs in there were reasonably out of sync with our style conventions, so I tried my best to get these sync'd up to match what I understand we would want the docs to look like if they were new contributions.

There are some warnings when I compile the docs locally, but then again, I also get warnings on master, so I went ahead and opened the PR to see if readthedocs has better luck than I.

PR Checklist

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

@brunobeltran brunobeltran force-pushed the collections-rcparams-links branch 2 times, most recently from 2afbe5f to f87cc48 Compare June 5, 2020 02:36
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Thanks for taking this up!

This is a lot to do and more to be done. I'm trying to strike a balance between making everything right (you probably have noticed that I have opinions on docstrings) and not commenting on every bit (some of which are not even your changes but just inherited from the current code). Please be patient and notify me when it get's too much - I might have a second or third round when reading this again.

Note: Code suggestions made here may need to be wrapped to hold the 79 char limit. It's hard to do this right in the github interface.

Comment on lines 33 to 35
A Collection represents a sequence of `~.patches.Patch` objects that the
library believes would be more efficient to draw together than
individually. For example, when a single path is being drawn repeatedly at
Copy link
Member

@timhoffm timhoffm Jun 5, 2020

Choose a reason for hiding this comment

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

Suggested change
A Collection represents a sequence of `~.patches.Patch` objects that the
library believes would be more efficient to draw together than
individually. For example, when a single path is being drawn repeatedly at
A Collection represents a sequence of `.Artist`\s. It is more efficient to
draw compared to using many individual `.Artist` objects. For example,
when a single path is being drawn repeatedly at

Note: You additionally have to make the docstring a raw string r``` because of the plural s for .Artists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this true though? While Collection inherits from Artist, it re-implements basically the entire Patch interface with plural method/property names. In addition, its properties default to patches. values from rc.

My impression from reading the code was that the only reason Collection doesn't inherit from Patch is because we wanted plural method names (but that might be an a posteriori justification, since I obviously wasn't around for the implementation).

The point is, while the Python Collection object is an artist, that part can be inferred from the class structure on the relevant docs page. The part that is not clear unless you literally read all the properties of Artist/Collection/Patch and compare them manually is that Collection semantically represents a collection of Patches to be drawn simultaneously (i.e. it has edgecolor, facecolor, etc.).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I hesitate to remove the wording about "may be" more efficient, since for most renderers, draw_path_collection is not necessarily any more efficient than individual draw_path calls (it just typically is whenever Collections are used correctly).

But I do see why you wanted to change it, the wording is pretty awkward, so I'll try changing it.

Copy link
Member

Choose a reason for hiding this comment

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

You may be mostly right with Patch. I was thinking of LineCollection which rather mimics a list of Line2D and thus went for the more general Artist. This is all a bit messy.

Is it reasonable to stick to Patch and just mention in LineCollection that it's different?

Performance: I didn't check, but I assume the advantage of collections is that you save a lot of python function calls, similar to how numpy is faster than a list of floats.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update the docs to refer to patch and make sure that LineCollection is clear about how it's basically the same thing but for Line2D.

I think you're right about the performance in theory, but in practice, backend base still breaks up draw_path_collection into individual draw_path calls anyway, so you don't gain performance unless the backend supports it, which was probably the justification for the original language.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if the backend is the bottleneck or creating the Artists, but in a quick test LineCollection is faster:

import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from matplotlib.collections import LineCollection
import numpy as np

xs = np.linspace(0, 1, 1000)
%%timeit
fig, ax = plt.subplots()
for x in xs:
    line = Line2D([x, x], [0, 1])
    ax.add_line(line)

445 ms ± 9.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

%%timeit
fig, ax = plt.subplots()

lc = LineCollection([[(x, 0), (x, 1)] for x in xs])
ax.add_collection(lc)

39.7 ms ± 1.13 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

@brunobeltran
Copy link
Contributor Author

Thanks @timhoffm for your detailed read! I'm happy to go through more rounds if you have more suggestions. Obviously there's a never-ending amount to do here, but if I feel like we start to get into "this should be a separate PR" territory, I'll let you know 😅

@brunobeltran brunobeltran force-pushed the collections-rcparams-links branch from e1cba73 to e98db08 Compare June 5, 2020 19:31
@brunobeltran brunobeltran force-pushed the collections-rcparams-links branch from 46d4a4b to 92c7399 Compare June 5, 2020 22:43
@brunobeltran
Copy link
Contributor Author

brunobeltran commented Jun 5, 2020

@timhoffm, round two of comments done, let me know if you have any more gripes with the changes (maybe after you get some sleep!) :)

@brunobeltran brunobeltran force-pushed the collections-rcparams-links branch from 92c7399 to 8bbdf68 Compare June 6, 2020 02:35

%(Collection)s
where *onoffseq* is an even length tuple of on and off ink lengths
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 odd-length sequences are allowed, see #17444. Or is that specifically not supported in collections?

Copy link
Contributor Author

@brunobeltran brunobeltran Jun 9, 2020

Choose a reason for hiding this comment

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

This was only written to match what is currently said in Line2D.set_dashes and Line2D.set_linestyle. I see that we now accept odd-length sequences in our backends, but all the user-facing documentation says otherwise. Are we sure that there's not other third-party backends that assume even length?

I'd personally prefer to make a separate PR fixing this since I'll want to fix it in 4-5 places throughout the documentation to more correctly describe how we do dashes...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EDIT: 12+ places where this needs changes. Would definitely prefer to do this in a separate PR.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

That's all now 😄.

@brunobeltran brunobeltran force-pushed the collections-rcparams-links branch from 8bbdf68 to b98990c Compare June 9, 2020 22:03
@brunobeltran brunobeltran added this to the v3.3.0 milestone Jun 9, 2020
@brunobeltran brunobeltran force-pushed the collections-rcparams-links branch from b98990c to eff114a Compare June 9, 2020 22:09
@brunobeltran
Copy link
Contributor Author

brunobeltran commented Jun 9, 2020

Nice doing business with you, @timhoffm. If you're happy to one-review merge this, I'll drop another PR on top of it right now to fix all the places where the docs claim we require an even-length onoffseq, but let me know if you see anything new that should still be fixed!

@brunobeltran brunobeltran force-pushed the collections-rcparams-links branch from eff114a to 7194e35 Compare June 9, 2020 23:12
@QuLogic
Copy link
Member

QuLogic commented Jun 9, 2020

This will need a rebase to fix doc builds. which you just did...

@brunobeltran brunobeltran force-pushed the collections-rcparams-links branch from 7194e35 to efd009f Compare June 9, 2020 23:35
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

On-off sequence descriptions can be fixed as a separate PR.

@timhoffm timhoffm merged commit 93c3224 into matplotlib:master Jun 10, 2020
@timhoffm
Copy link
Member

Thanks for bringing this forward and patiently working through all my comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants