-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Rewrite of the entire legend documentation, including tidy ups of code and style to all things "legend". #2442
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
@@ -75,15 +80,23 @@ def teardown_class(cls): | |||
def test(self): | |||
self._func() | |||
|
|||
|
|||
def cleanup(func): |
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.
@mdboom - pinging you here. I did this so I could have methods which get cleaned up. I've got some ideas on how to tidy up the whole suite of testing decorators, but I was doing my best to restrain from doing them in this 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.
I think this code predated functools (Python 2.5), so I'm glad to modernize it.
|
||
To automatically generate the legend from labels:: | ||
line, = ax.plot([1, 2, 3], label='Inline label') |
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.
There's a coma after line
. Is that wanted (is that valid python syntax?)?
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 is to un-pack the length one list that plot
returns so line
is a Line2D
object, not a list
.
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.
Ah, nice. Thanks
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.
On 2013/09/20 3:44 AM, Varoquaux wrote:
In lib/matplotlib/axes/_axes.py:
To automatically generate the legend from labels::
line, = ax.plot([1, 2, 3], label='Inline label')
Ah, nice. Thanks
It's a common idiom, and I use it, but with hesitation; it "looks wrong"
at first glance, as you noticed. The alternative, explicitly indexing
with [0] at the end, is less concise but more visually obvious.
Therefore it might be preferable in documentation intended for newcomers.
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 rather like the the idiom. I would suggest adding a note explaining it before changing it to [0].
I agree with this in concept -- I probably won't have a chance to review it properly until after tagging 1.3.1, however. |
same height, set to ``[0.5]``. Default ``[0.375, 0.5, 0.3125]``. | ||
|
||
markerscale : None or int or float | ||
The relative size of legend markers compared with the originally |
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.
Spelling mistake? I think there's only one l in "originally".
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 is double "l" in English. I couldn't find whether there is an American spelling (http://www.merriam-webster.com/dictionary/originally)
This is nice work! The documentation is much better. Thanks! |
the first two argument of the legend call.:: | ||
Not all handles can be turned into legend entries automatically, | ||
so it is often necessary to create an artist which *can*. Legend handles | ||
don't have to exists on the Figure or Axes in order to be used. |
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.
typo: exists
-> exist
I've been a little busy lately and not been able to bang the drum for this PR - sorry for letting it slip. I've rebased, and believe I've addressed the comments above. Lets extend the merge date to this Friday - the 1st of November. |
@mdboom - any ideas on what's up with the tests?
As far as I'm aware, I've not done anything to upset mlab, but you can never be certain I suppose. |
Hmm... not sure. I've restarted the tests just for good measure... if still failing, I'll investigate further. |
I'm stumped by the test failures (and can't reproduce them here). Maybe we try reverting the change to |
This looks vaguely like the failures that are showing up on #2236 in the 3.x builds (in that there are errors that the tests don't exist). |
@pelson any progress on this? |
I've rebased - the failing test wasn't to do with this change as far as I can see. Hopefully the tests will work now. |
I've just rebased and I think this is good to go. Anyone willing to merge? |
internals are revised to support | ||
The :meth:`~matplotlib.axes.Axes.get_legend_handles_labels` function returns | ||
a list of handles/artists which exist on the Axes which can be used to | ||
generate entries for the resulting legend. |
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.
There should be a sentence or clause here hedging that this will not work for all artists.
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.
a list of handles/artists which exist on the Axes which can be used to generate entries for the resulting legend.
There is no hedging needed. The function always works, it just doesn't always return all of the artists that have been added to the axes. I do go on to mention that not all artists can be drawn in a legend, and ideally would keep the two paragraphs separate.
Do you still want me to do this?
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 don't think it is clear that it will only return the artists which have registered handlers. I want to put a reference to that other paragraph here so people realize that they may need to keep reading.
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.
Ok. I'm on it.
The loc itslef can be a 2-tuple giving x,y of the lower-left corner of | ||
the legend in axes coords (*bbox_to_anchor* is ignored). | ||
Specific lines can be excluded from the automatic legend element | ||
selection by defining a label starting with an underscore. |
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.
doc line related to comment about _ above.
Ok, I've added a commit on top of ceda68f - thanks for your thorough review @tacaswell. |
Note - this doesn't merge cleanly (whats new perhaps) - so rather than re-base and force you to have to re-read everything, I will merge this manually once I've got your 👍 @tacaswell. |
I left one minor comment, but other than that 👍 Should probably change the note in |
and style to all things "legend".
I decided to rebase @tacaswell - do you want to merge? |
Rewrite of the entire legend documentation, including tidy ups of code and style to all things "legend".
Woo-ho - thanks @tacaswell - hopefully I will stop being asked all the time how to do legends 😄! |
Unlikely. Legends have a lot of moving parts. |
First off - apologies for such a big PR.
This work represents several days effort in rationalising and extending the legend documentation throughout matplotlib. I've focused almost entirely on improving the documentation, but in the process I've also cleaned up the code and simplified some interfaces (in the interest of clearer documentation).
There are changes to some example files which may not seem relevant, but I've gone through the entire gallery to identify the necessary legend related plots, and as a result have removed some of the duplicates which shouldn't have been there in the first place.
Important:
I'd like to put an alternative perspective on the way we review this PR given how much effort this review will require. Instead of waiting for 👍s - I'd like to put a deadline of 14 days (4th October 2013) to have any 👎s, and provided any review actions are complete, either I, or some other kind soul, will merge this. I think this approach might work well for primarily documentation type changes and this is a good place to trial it out.
Thanks!