10000 DOC improved subplots' docstring by NelleV · Pull Request #7232 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

DOC improved subplots' docstring #7232

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 6 commits into from
Oct 13, 2016
Merged

DOC improved subplots' docstring #7232

merged 6 commits into from
Oct 13, 2016

Conversation

NelleV
Copy link
Member
@NelleV NelleV commented Oct 7, 2016
  • the dostring is now in numpydoc format.
  • added an extra line in the examples to showcase accessing the axes returned array

closes #7230

Here is how it now looks rendered:

subplots

@NelleV
Copy link
Member Author
NelleV commented Oct 7, 2016

ping @stefanv @michaelpacer

@NelleV NelleV changed the title DOC improved subplots' docstring [MRG] DOC improved subplots' docstring Oct 7, 2016
>>> ax1.set_title('Sharing Y axis')
>>> ax2.scatter(x, y)

Creates four polar axes, and access them throught the returned array
Copy link
Contributor

Choose a reason for hiding this comment

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

accesses

Copy link
Contributor

Choose a reason for hiding this comment

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

through

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI, that's the lack of coffee…

Copy link
Contributor
@stefanv stefanv left a comment

Choose a reason for hiding this comment

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

Yes, this is great, thanks @NelleV

>>> ax1.set_title('Sharing Y axis')
>>> ax2.scatter(x, y)

Creates four polar axes, and access them throught the returned array
Copy link
Contributor

Choose a reason for hiding this comment

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

through

- If True, extra dimensions are squeezed out from the returned axis
object:
- if only one subplot is constructed (nrows=ncols=1), the
resulting single Axis object is returned as a scalar.
Copy link
Member

Choose a reason for hiding this comment

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

This does not look indented correctly, and appears to render wrong (and same for the following two.)

Returns:

Returns
-------
fig, ax : tuple
Copy link
Member

Choose a reason for hiding this comment

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

These can be split into separate entries, right?

@NelleV
Copy link
Member Author
NelleV commented Oct 7, 2016

There is still an indentation problem, but I am not seeing it…

@mpacer
Copy link
mpacer commented Oct 7, 2016

When I look at the docstring, it looks like exactly what Stefan and I were talking about (and what I'd been looking for). But the rendered image included in the PR seems to cut off before the new example is displayed.

Fortunately, that image doesn't matter while the docstring does. Thanks @NelleV!

:meth:`~matplotlib.figure.Figure.add_subplot` call used to
create each subplots.
:meth:`~matplotlib.figure.Figure.add_subplot` call used to create each
subplots.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe "create each subplot"?

>>> ax.plot(x, y)
>>> ax.set_title('Simple plot')

Creates two subplots and unpack the output array immediately
Copy link
Contributor

Choose a reason for hiding this comment

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

unpacks

ncols > 1 then the y tick labels won't be displayed on any of
the plots but the ones on the first column.

squeeze : bool, optional, default: True
Copy link
Member Author

Choose a reason for hiding this comment

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

I think there is an indentation problem around here, but I can't see it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I found the problem and fixed it.

- the dostring is now in numpydoc format.
- added an extra line in the examples to showcase accessing the axes returned array

closes #7230

fig, ax : tuple
ax : axis or array of axis objects.
Copy link
Member

Choose a reason for hiding this comment

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

They're really Axes objects, or more specifically AxesSubplot objects. An Axis object is the individual x- or y-axis.


Examples::
Creates just a figure and only one subplot.
Copy link
Member

Choose a reason for hiding this comment

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

I would go with imperative tense ("Create just ..."); the sharing sections use this tense as well. Also, this is the only one with a period at the end.


# Four polar axes
plt.subplots(2, 2, subplot_kw=dict(polar=True))
Share a X and Y axis with all subplots
Copy link
Member

Choose a reason for hiding this comment

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

"Share both", I think.

- "all" has the same effect as True.
- "none" has the same effect as False.
- If "row", each subplot row will share a X axis.
- If "col", each subplot column will share a X axis. Note that if
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment (which is also present for "if True...") could possibly be factored out to the end of the list: "if the X axis is shared across columns (sharex=True or sharex="col"), then etc." (and similarly for sharey).


Note that if the x-axis is shared across rows (sharex=True or
sharex="col") and nrows > 1 then the x tick labels won't be displayed
on any of plots but the ones on the bottom row.
Copy link
Contributor

Choose a reason for hiding this comment

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

Upon further reflection, I think you can state this more simply as "Note that if the x-axis is shared across rows (...), then the x tick labels will only be displayed on the bottom row" (skipping the remark about nrows > 1).
(By the way let's be consistent between "x-axis" and "X axis" (I prefer the former)).

@QuLogic
Copy link
Member
QuLogic commented Oct 10, 2016

Can you update the figure at the top?

The AppVeyor fail appears unrelated.

@NelleV
Copy link
Member Author
NelleV commented Oct 10, 2016

I am not sure what figure you are referring to.

@QuLogic
Copy link
Member
QuLogic commented Oct 10, 2016

Of the rendered documentation in the first post (not in the docs themselves.)

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Oct 10, 2016
@tacaswell tacaswell changed the title [MRG] DOC improved subplots' docstring [MRG+1] DOC improved subplots' docstring Oct 10, 2016
@NelleV
Copy link
Member Author
NelleV commented Oct 11, 2016

Here it is (it's tiny as I had to zoom out a lot to be able to take a reasonable size screenshot)

subplots

@efiring
Copy link
Member
efiring commented Oct 11, 2016

Sorry to be late in commenting on this, but I am wondering whether you could condense the docstring by treating nrows and ncols together, and similarly with sharex and sharey. There is value in making docstrings as concise as possible without losing important info.


sharex : bool or string, optional, default: False
- If True, the x-axis will be shared amongst all subplots.
- If False, no axis will be shared amongst subplots.
Copy link
Member

Choose a reason for hiding this comment

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

axis -> x-axis

@NelleV
Copy link
Member Author
NelleV commented Oct 11, 2016

@efiring nrows and ncols, certaintly. The sharex sharey condensed is actually very hard to read (and to write)

@efiring
Copy link
Member
efiring commented Oct 11, 2016

Maybe something like the following:

sharex, sharey : bool or string, {'row', 'col', 'all', 'none'}, default is False
    Controls sharing of properties among x or y axes. Axis properties may
   
10000
 be shared among all subplots (True or 'all'), among none (False or 'none'),
    or among subplots by 'row' or by 'column'.  When subplots have shared y
    axes along a row, the y tick labels have their `visible` property set to False
    on all but the first column; similarly, when subplots have shared x axes
    along a column, only the x tick labels are visible only on the bottom 
    subplot.

@tacaswell
Copy link
Member

I tried to just push a commit with my pedandtic word changes, but it would not let me.

index de97b5d..2205698 100644
--- a/lib/matplotlib/figure.py
+++ b/lib/matplotlib/figure.py
@@ -1056,7 +1056,7 @@ class Figure(Artist):

         squeeze : bool, default: True
             - If True, extra dimensions are squeezed out from the returned
-              axis object:
+              object:

                 - if only one subplot is constructed (nrows=ncols=1), the
                   resulting single Axes object is returned as a scalar.
diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py
index d304876..e112a27 100644
--- a/lib/matplotlib/pyplot.py
+++ b/lib/matplotlib/pyplot.py
@@ -1077,7 +1077,7 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
         subplots of the first column.

     squeeze : bool, optional, default: True
-        - If True, extra dimensions are squeezed out from the returned Axes
+        - If True, extra dimensions are squeezed out from the returned
           object:

             - if only one subplot is constructed (nrows=ncols=1), the

@NelleV
Copy link
Member Author
NelleV commented Oct 12, 2016

@tacaswell that's weird: the tick box to allow edits from maintainers is ticked…

@NelleV
Copy link
Member Author
NelleV commented Oct 12, 2016

Before I do yet another commit, can you be more specific about the word change you'd like? The review and patch aren't the same.

@efiring
Copy link
Member
efiring commented Oct 12, 2016

@NelleV, and other reviewers, please reconsider your rejection of my attempt to make a much shorter docstring. I believe we need to think again about what makes a good docstring. Consider what you want to see, either in the terminal or in the browser: a concise description, with the most critical information appearing early. It should not insult the intelligence of the viewer, so it should minimize unnecessary repetition. Some standardization of structure, such as that imposed by numpydoc, is OK, but the text should look like it was written by a person, not an algorithm.

With those ideas in mind, I think that we should use lists sparingly, with minimal nesting, because they gobble space. And I don't see that a combined description of sharex and sharey is necessarily any harder or slower to read and digest than the present separate description. Surely my draft suggestion can be improved, but I think it illustrates a better path.

@afvincent
Copy link
Contributor

I am inclined to agree with @efiring about the fact that a too long or a too repetitive docstring can be hard to read or navigate, and that we should value docstring conciseness when it does not harm the docstring readibility nor the informations it provides. Nonetheless I still find first level lists to be useful to provide fast and random access to descriptive information.

In the present case, as the description of sharex and sharey parameters overlap significantly, I believe one could achieve some kind of factorization. Here is a draft that is inspired from both @NelleV and @efiring proposals:

    sharex, sharey : bool or {'none', 'all', 'row', 'col'}, default: False
        Controls sharing of properties among x (`sharex`) or y (`sharey`) axes:
            - If True or 'all', x- or y-axis will be shared among all subplots.
            - If False or 'none', all subplot x- or y-axis will be independant.
            - If 'row', each subplot row will share an x- or y-axis.
            - If 'col', each subplot column will share an x- or y-axis.

        When subplots have a shared x-axis along a column, only the x tick
        labels of the bottom subplot are visible.  Similarly, when subplots
        have a shared y-axis along a row, only the y tick labels of the first
        column subplot are visible.

It is 3 lines longer than the super squeezed version, but only half the length of the non-factorized one. To be honest, I struggled a bit to fit each item of the list into a single (PEP8) line: I hope English is still correct.

@efiring
Copy link
Member
efiring commented Oct 12, 2016

@afvincent, thank you, that looks good to me. Recommended tweak: Each leading "If" could be removed, and the first comma replaced by a colon, e.g.,

    - True or 'all': x- or y-axis will be shared among all subplots.

In the second item (False), "all" -> "each".

@NelleV
Copy link
Member Author
NelleV commented Oct 12, 2016

I agree that shorter docstrings are in general better.
I've pushed the change.

Where I am more concerned is the amount of comments and debates on a pull request that original meant to add an example to the docstring. With half of the effort on that pull request, we probably could have done 5 more improvements on other docstrings.

@efiring
Copy link
Member
efiring commented Oct 12, 2016

On 2016/10/12 6:55 AM, Nelle Varoquaux wrote:

Where I am more concerned is the amount of comments and debates on a
pull request that original meant to add an example to the docstring.
With half of the effort on that pull request, we probably could have
done 5 more improvements on other docstrings.

Good point. This is a real problem. I think that what I should have
done was to wait for your PR to be merged and then use a separate PR to
propose additional modifications.

- True or 'all': x- or y-axis will be shared among all
subplots.
- False or 'none': all subplot x- or y-axis will be
independant.
Copy link
Contributor

Choose a reason for hiding this comment

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

@NelleV I apologize: it seems I introduced a typo here. I think it should be "independent" instead of "independant" (a false friend for a French speaker…). BTW @efiring suggested that "each subplot x- or y-axis" might be better than "all subplot x- or y-axis".

- True or 'all': x- or y-axis will be shared among all
subplots.
- False or 'none': all subplot x- or y-axis will be
independant.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same minor remark: "independant" ← "independent", and "all" ← "each".

@QuLogic
Copy link
Member
QuLogic commented Oct 12, 2016

Where I am more concerned is the amount of comments and debates on a pull request that original meant to add an example to the docstring. With half of the effort on that pull request, we probably could have done 5 more improvements on other docstrings.

That's not all it did though, and sometimes things need to be discussed before they get to a good consensus. It's easier to do so on one PR than a whole bunch of them, especially if they're all working on the same code/docs.

@NelleV
Copy link
Member Author
NelleV commented Oct 13, 2016

@QuLogic First, these discussions should not happen on PRs, as it doesn't include the whole community. Second, that's not the first PR were this happens: most of the documentation PRs I have seen take a very long time to be merged. It is much easier to nitpick and bikeshed on a docstring than on tiny code patch that fixes a bug hard to track (#7214 has been opened for 9 days, yet only has one approval and potentially three people looking at it).
And that does account for the "discouragement factor" of the potentially new contributor, who'll probably never submit a patch again after seeing this.

You should check Pieter Hintjens' view on the question: http://hintjens.com/blog:106
Thought I don't agree with him that all pull requests should merge without doing code review, his opinion is worth reading and thinking about.

sharex, sharey : bool or {'none', 'all', 'row', 'col'}, default: False
Controls sharing of properties among x (`sharex`) or y (`sharey`)
axes:
- True or 'all': x- or y-axis will be shared among all
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 you need a blank line here because sphinx

Copy link
Member Author

Choose a reason for hiding this comment

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

yep… I fixed that (but haven't tested) and took this opportunity to rebase.

@tacaswell
Copy link
Member

I think that the threshold on documentation only PRs should be "Does this make it better and is not wrong?", if yes then merge.

Documentation seems to be much harder to collaborate on via PR comments than code. I suggest that the next time we see one of these PRs getting very bike sheddy, the (3 most) interested parties arrange for some sort of real-time collaboration (google docs / hackpad / whatever) + voice and hash it out.

If sphinx passes, I intend to merge this.

@tacaswell tacaswell merged commit 6ad368b into matplotlib:master Oct 13, 2016
tacaswell added a commit that referenced this pull request Oct 13, 2016
DOC: improved subplots' docstring

Conflicts:
    lib/matplotlib/figure.py
      - figure.py subplots method does not exist on 2.x branch
@tacaswell
Copy link
Member

Thanks everyone!

backported to v2.x as 2c7be7c

@QuLogic QuLogic changed the title [MRG+1] DOC improved subplots' docstring DOC improved subplots' docstring Oct 15, 2016
@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0 (style change major release) Dec 7, 2016
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.

subplots docstring: no example of NxN grid
10 participants
0