Skip to content

Improve table docs #12218

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 1 commit into from
Nov 22, 2018
Merged

Improve table docs #12218

merged 1 commit into from
Nov 22, 2018

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Sep 22, 2018

PR Summary

Changes:

  • Documented Cell.
  • Rewrote the module docstring.

Do we need the author, copyright, license stuff in the module docstring? Or are the redundant, because this stuff is handled on the project-level?

I could not make sense of the following two sentences in the module docstring. Therefore I removed that information. If anyone knows what these should mean, I'd be happy to add a more clear description.

The grid need not be rectangular

You can add additional cells outside this [(max_row, max_col)] range to have convenient
ways of positioning more interesting grids.

@anntzer
Copy link
Contributor

anntzer commented Sep 22, 2018

See 735f308#diff-3ca3e0d4e31b414f1e771501e9bf69d3L3 for how I handled authorship issues. I have no problem with leaving in who originally contributed the module, but they're obviously not the sole author anymore.

@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commented Sep 23, 2018

I interprete the sentence

The grid need not be rectangular. You can add additional cells outside this [(max_row, max_col)] range to have convenient ways of positioning more interesting grids.

such that you are not restricted to the initial grid of the table. E.g. if you created a 11x2 table, you may still add cells outside the range of [0,1] columns and [0,10] rows. E.g.

image

Code
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

c1 = ["pale", "dark"]
c2 = ["green", "turquoise"]
c3 = ["crimson", "bisque"]

a = [["".join((c1[i%2],c2[(j+i)%2])) for i in range(2)] for j in range(11)]

table = ax.table(cellColours=a, loc="center left", colWidths=[0.05]*2)
h = table.get_celld()[(0,0)].get_height()
for j in range(5):
    for i in range(1+j,10-j):
        table.add_cell(i,j+2, 0.05, h, facecolor=c3[(i+j)%2])
        table.add_cell(i,10-j, 0.05, h, facecolor=c3[(i+j)%2])
        table.add_cell(12-j,i+1, 0.05, h, facecolor=c3[(i-j-1)%2])
    table.add_cell(-3,j+4, 0.05, h, facecolor="g"+["","old"][j%2])
        
plt.show()

@timhoffm
Copy link
Member Author

@ImportanceOfBeingErnest Thanks, I've added that information to the Table class docstring.

@timhoffm
Copy link
Member Author

See 735f308#diff-3ca3e0d4e31b414f1e771501e9bf69d3L3 for how I handled authorship issues. I have no problem with leaving in who originally contributed the module, but they're obviously not the sole author anymore.

@anntzer Thanks, I've now used that style and converted author and copyright there. I've removed the license, because it just says "matplotlib license", which is the license of the whole project anyway. Not sure if we have to keep the copyright notice.

@anntzer
Copy link
Contributor

anntzer commented Sep 23, 2018

No opinion there; @tacaswell?

@jklymak jklymak modified the milestones: v3.0.x, v3.0.0-doc Oct 3, 2018
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Seems fine. Not sure about the author/copyright stuff either - we definitely don't do this anymore.

@anntzer
Copy link
Contributor

anntzer commented Oct 6, 2018

Letting @tacaswell have a look at the copyright issue, if he cares.

@timhoffm
Copy link
Member Author

timhoffm commented Oct 13, 2018

@tacaswell explicit question: What to do with author/copyright notices in docstrings:

https://github.com/matplotlib/matplotlib/pull/12218/files#diff-cd21097aa8cce79ca8a23b7f52c48f99

  • Keep them in the docstring
  • Move them from the docstring to a comment in the file, so that they do not show up in the docs but are still in the source code
  • Remove them because they are not necessary in that context

@tacaswell
Copy link
Member

tacaswell commented Oct 14, 2018

I do not think we can remove them.

I think the best path forward is to add "Original code by:" above it and "subsequent changes are copyright Matplotlib Developers" below, and to move it out of the docstring.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

copyright changes, anyone can dismiss this.

@timhoffm
Copy link
Member Author

timhoffm commented Nov 1, 2018

Rebased.

PAD = 0.1 # padding between text and rectangle

PAD = 0.1
"""Padding between text and rectangle."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of prefer leaving this as inline comment (fwiw).
(As a side note, compare with the padding of Annotations, which is also hardcoded

                    pad = renderer.points_to_pixels(4)

)

Copy link
Member Author

@timhoffm timhoffm Nov 2, 2018

Choose a reason for hiding this comment

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

Since this is a public attribute, it shows up in the docs

I very much prefer that every element in the docs has a description. This is achived using the docstring

I would be fine not documenting PAD, but only if we also remove it from the docs (either by excluding explicitly (not sure if that's feasible with autodoc in this context), or preferably by renaming to _PAD.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I didn't realize sphinx would pick it up. I guess that works, then...

@@ -42,7 +71,7 @@ def __init__(self, xy, width, height,
):

# Call base
Rectangle.__init__(self, xy, width=width, height=height,
Rectangle.__init__(self, xy, width=width, height=height, fill=fill,
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that's an intended new feature (respecting fill instead of dropping 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.

Yes. I assume that is was accidentally omitted. There's no point in having fill in __init__ if it's silently dropped.

@@ -124,18 +154,27 @@ def _set_text_position(self, renderer):
self._text.set_position((x, y))

def get_text_bounds(self, renderer):
""" Get text bounds in axes co-ordinates. """
"""
Return the bounds of the text as *(x, y, width, height)* in table
Copy link
Contributor

Choose a reason for hiding this comment

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

"Return text bounds etc." fits in one line.

The table consists of a grid of cells, which are indexed by (row, column).

For a simple table, you'll have a full grid of cells with indices from
(0, 0) to (max_rows-1, max_cols-1), in which the cell (0, 0) is positioned
Copy link
Contributor

Choose a reason for hiding this comment

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

(n_rows-1, n_cols-1) or (max_row, max_col) (by definition max_foo is the largest value of foo...).

@@ -29,9 +29,38 @@

class Cell(Rectangle):
"""
A cell is a `.Rectangle` with some associated text.
A cell is a `.Rectangle` with some associated `.Text`.
Copy link
Contributor

Choose a reason for hiding this comment

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

extra space after "is a"

@anntzer anntzer merged commit 3c702c4 into matplotlib:master Nov 22, 2018
@lumberbot-app
Copy link

lumberbot-app bot commented Nov 22, 2018

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.0.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 3c702c495d60c41e940855d1e80d9de3cd75c49e
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #12218: Improve table docs'
  1. Push to a named branch :
git push YOURFORK v3.0.x:auto-backport-of-pr-12218-on-v3.0.x
  1. Create a PR against branch v3.0.x, I would have named this PR:

"Backport PR #12218 on branch v3.0.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

@lumberbot-app
Copy link

lumberbot-app bot commented Nov 22, 2018

Something went wrong ... Please have a look at my logs.

It seem that the branch you are trying to backport to does not exists.

@anntzer anntzer modified the milestones: v3.0.0-doc, v3.1 Nov 22, 2018
@anntzer
Copy link
Contributor

anntzer commented Nov 22, 2018

Sorry, didn't pay attention to the milestone. Made it 3.1 as it touches .py sources (not against someone doing a manual backport to 3.0.x but doesn't seem urgent either).

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.

5 participants