-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow figure.legend to be called without arguments #7811
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
Current coverage is 62.17% (diff: 73.33%)@@ master #7811 diff @@
==========================================
Files 174 174
Lines 56050 56119 +69
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 34806 34894 +88
+ Misses 21244 21225 -19
Partials 0 0
|
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've added some minor comments, but it looks good overall. There is just a what's new item missing.
It'd also be great if we could improve the error message.
@@ -1,19 +1,19 @@ | |||
import numpy as np |
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.
While you are at it, do you mind adding a docstring to give this example a title and explain what it does? See http://matplotlib.org/devdocs/devel/MEP/MEP12.html for examples.
fig = plt.figure() | ||
ax1 = fig.add_axes([0.1, 0.1, 0.4, 0.7]) | ||
ax2 = fig.add_axes([0.55, 0.1, 0.4, 0.7]) | ||
fig, axs = plt.subplots(1, 2) |
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.
👍
@@ -1261,38 +1261,57 @@ def draw_artist(self, a): | |||
def get_axes(self): | |||
return self.axes | |||
|
|||
def legend(self, handles, labels, *args, **kwargs): | |||
def legend(self, *args, **kwargs): |
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.
While you are at it, do you mind migrating this to a numpydoc compatible docstring?
(I can also do it if you don't mind me pushing to your branch).
kwargs['loc'] = loc | ||
|
||
else: | ||
raise TypeError('Invalid arguments to 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.
Do you think we could have an error message more specific? It's quite obscure right now.
I like better "Invalide number of arguments to legend. Possible arguments are (etc)"
And thanks for the patch :) |
Hold on a minute, not quite done! (sorry for the early push) |
Okay, that should be everything (I think!) |
'upper left' 2 | ||
'lower left' 3 | ||
'lower right' 4 | ||
'right' 5 |
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 wonder why there's this seemingly extra location.
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 it's the same in axes.legend() too.
``legend.handlelength`` :data:`rcParam<matplotlib.rcParams>`. | ||
|
||
handletextpad : float or None | ||
The pad between the legend handle and text. |
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.
pad -> padding
parameters. The dimensions of these values are given as a fraction | ||
of the fontsize. Values from rcParams will be used if None. | ||
borderaxespad : float or None | ||
The pad between the axes and legend border. |
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.
pad -> padding
|
||
borderpad : float or None | ||
The fractional whitespace inside the legend border. | ||
Measured in font-size units. |
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 would add this on to the end of the previous sentence, and do the same in all the following parameters: The fractional whitespace inside the legend border, measured in font-size units.
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 the 2 comments below are on bits of docstring directly copied from axes.legend(), so should probably fix them there at some point too.
fig, axes = plt.subplots(2) | ||
axes[0].plot([0, 1], [1, 0], label='x', color='g') | ||
axes[0].plot([0, 1], [0, 1], label='y', color='r') | ||
axes[1].plot([0, 1], [1, 0], label='y', color='r') |
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.
What happens when the labels are the same, but the style is different? I believe it should be separate, but it's not tested.
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.
Yep, seems fine, added it in the image test
=============== ============= | ||
Location String Location Code | ||
=============== ============= | ||
'best' 0 (currently not supported for figure legends) |
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.
Just omit this line if it is not supported?
d21efe0
to
12c5be9
Compare
Okay, there goes the un-used location code and with it the PEP8 violation. I've also squashed it all down into one commit since there were at least 2 changes to the test figures previously. |
handles = [] | ||
labels = [] | ||
|
||
def in_handles(h, l): |
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 would be nice to leave a comment as to what's happening here (at least it's not obvious to me at all...).
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.
How's that? If you can think of better wording feel free to push to my branch.
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.
Sounds good. Typo: "consdier".
I would make it a comment rather than a docstring to save some whitespace, and get rid of the whitespace between the try... catch blocks (right now it's very spread out).
LGTM. Someone else wants to re-review it after the (minor) changes? |
LGTM. I'll wait until appveyor's finished before merging. |
This appears to break invocations like |
This supersedes #2128.
(p.s. I can squash this once it's all been reviewed)