-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOCS: add examples of how one "should" use Bbox #17090
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
Conversation
b8cd9e4
to
5b8134f
Compare
|
||
>>> Bbox.intersection(Bbox.null(), Bbox.null()) | ||
Bbox([[-inf, -inf], [inf, inf]]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a reasonable behavior? Seems to contradict the semantics of update_from_data_xy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah part of why I'm documenting this is because this behavior was very unexpected. I expected Bbox.null()
to be the "zero" object of the intersection/union ring over the Bbox's.
But it's not technically a bug per se since it's not documented, so I didn't open an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, I'd be happy to make a separate PR to fix this "bug", if other people also agree that it shouldn't be this way, but don't want to get bogged down talking about deprecation timelines, etc. here, would rather open a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and below clearly look like bugs, but I'm fine documenting these here and changing them later.
This looks like a valuable addition, but not sure about the format. Should this be an example, and the bbox docs refer to the example? We dont' have a lot of docs that scroll through the whole functionality as a series of examples in the actual docstring. |
@jklymak I would guess this is less intrusive, since this are largely "internal-facing" docs, and so a new developer is more likely to |
I think this renders nicely: https://34270-1385122-gh.circle-artifacts.com/0/doc/build/html/api/transformations.html?highlight=bbox#matplotlib.transforms.Bbox Given the internal facing nature of this, I think it also is nice to have the algebra directly in the source (not linked). I'm in favor of documenting the behavior and then sorting out if we can fix it (and if it changed recently) in a follow up PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we only need 1 approval for doc changes, but I'm going to hold off merging as Tim and Jody have some concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with adding these examples here. It's a bit lengthy but still ok, You might want to add sections for structuring (technically there are no subsections in numpydoc, but we can use bold paragraphs as subtitles:
Examples
--------
**Creating Bboxes**
...
**Modifying Bboxes**
...
Feel free to choose other subsection titles.
While this could be placed externally and linked, I don't think we have a dedicated suitable part of the docs to put it. There are the Examples which illustrate exemplary use cases, and there are the Tutorials which give a narrative introduction into a topic. The third and IMHO missing category would be comprehensive documentation of concepts in matplotlib, which are descriptive rather than narrative. This kind of docs is currently spread across various locations, some in Examples, some in tutorials, some in module docstrings and some in dedicated .rst files. I'd like to clean that up at some point, but up until then it's fine to have this in the docstring.
I'm glad to see that I'm not the only one that feels this is the main missing component. My thought was that by adding more fleshed out documentation to a few key classes little by little, we might eventually reach a point where this kind of "concept" documentation can be made surprisingly easily by stitching together the docstrings to these conceptually crucial classes in a way that's descriptive instead of tutorial/narrative driven. Anywho, incorporated all your suggestions @timhoffm, thanks for the improvements! |
Very tangential note re: subsections in long docstrings: see numpy/numpydoc#216 if you have time to waste in another rabbit hole -- or perhaps try |
It could be interesting to investigate other subsection techniques. But that would be something for a separate PR; we've already used the bold paragraph way in a number of docstrings. And IMHO it's more readable in the the source than ReST directives. |
Removed the unnecessarily inflammatory language, thanks @timhoffm. I assume codecov is still broken? Since this is a docs PR lol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be nitpicky, but I like to have the docs as clear as possible so that it‘s easy to understand for the user.
lib/matplotlib/transforms.py
Outdated
>>> box | ||
Bbox([[1.0, 1.0], [1.0, 1.0]]) | ||
|
||
.. warning:: Not setting ``ignore`` can have unexpected results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you be more specific about this? Are you referring to the somewhat questionable behavior that the last state of ignore
is used by default? If so, use something like:
It is recommended to always specify
ignore
explicitly. If not set, the value of ignore from the previous call will be reused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm even more worried about users trying to use the fact that it's supposed to be the previous call's ignore value that is reused.
In practice, .ignore
could have been called, or external code that touched the bbox could have changed the default value.
That happened to me when coding #16832, and it was a pain to track down.
I updated the warning to be very specific.
lib/matplotlib/transforms.py
Outdated
|
||
**Create from collections of points** | ||
|
||
The "empty" object for accumulating Bboxs is the null bbox, which has |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more „properties of the null box“ and might be better moved there. While you are using the null box in the following example, the null boxes dimensions are not relevant there. Without knowing what a null box is, you can still „create a null box and update it with the points“.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be moved there, but I think it makes sense for the user to see "why" the null Bbox is the "empty" object. I mean they can always read past this information if it's not relevant for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My update is a compromise that doesn't emphasize the properties of the null Bbox until later, but still prints it, so that the user can infer why it is "like" the empty set if they "feel" like thinking that hard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you feel strongly that the new version still feels out-of-order, I'll change it :)
Appreciate the nitpickyness @timhoffm, I am happy for this to take as long as it needs for us to get the best docs out! Let me know if you have any further qualms about the new version. |
Tangential tangential, but we've been putting some conceptual stuff in the blog at the moment (https://matplotlib.org/matplotblog/) but also like half of the entries in the tutorial section are really conceptual overviews 🤷♀️ |
Git's auto-accept-code-review button dumped whitespace all over the place, had to rebase, sorry. |
PR Summary
A tutorial on how to use something as simple as a
Bbox
, seems unecessary right? But subtle, innocuous word choices in the docs ofBbox
made it really hard for me to discover the "intended" workflow.For example, it took a while to notice that
Bbox.null()
exists when just scrolling through, even though by any measure this is probably the most "important" Bbox. Noticing thatupdate_from_path
was looking at just the vertices of the path, and not the "true" path extents, required me to dive into_path.h
, which also felt like a failure of documentation (fixed in #16832, which hopefully gets merged any day now). I could go on, but the point is that a short "Examples" section in the docstring would have solved all these issues.PR Checklist