-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
add which kwarg to autofmt_xdate #8157
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
lib/matplotlib/figure.py
Outdated
The horizontal alignment of the xticklabels | ||
|
||
which : {None, 'major', 'minor', 'both'} | ||
Selects which ticklabels to return |
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.
'which ticks to rotate'?
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 'which' is referring to is not clear or is this a suggestion to change 'return' to 'rotate'?
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.
Tom meant that you should change "Selects which ticklabels to return" to "Selects which ticklabels to rotate"
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.
Done.
If there are no tests, then you are in luck as you get to meaningfully increase our test coverage! It is a |
No tests found in test_dates as well. |
I agree with @tacaswell that a test is needed for this new feature. |
lib/matplotlib/tests/test_figure.py
Outdated
minors = [1,2,3,4,5,6,7] | ||
|
||
x = mdates.datestr2num(date) | ||
y = mdates.datestr2num(time) |
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 looks like you have a mix of tabs and spaces, can you please make them all spaces (many editors have tools to help with this, and a minimum find and replace `\t' -> ' '.
Can you also drop a file in https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new so that this gets properly advertised? |
lib/matplotlib/figure.py
Outdated
""" | ||
allsubplots = all(hasattr(ax, 'is_last_row') for ax in self.axes) | ||
if len(self.axes) == 1: | ||
for label in self.axes[0].get_xticklabels(): | ||
for label in self.axes[0].get_xticklabels(False, which): |
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.
You can also pass this in as get_xticklabels(which=which)
which is less cryptic than the leading False
.
Which we support both minor
and which
is an interesting question...which the answer to is it is my fault: 08d961a 😞 .
whats the problem here? PEP8? |
@patniharshit yeah you've got a number of PEP8 violations. |
"AppVeyor build failed" what does this mean? BTW while fixing for PEP8 violations in my code I noticed several other files also have these violations. |
@patniharshit Travis CI tests the code on a linux operating system. AppVeyor tests the code on Windows. However, AppVeyor (the system) is generally broken for us right now, so we're not too concerned that the build failed. |
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 have the availability and desire, I'd recommend two things:
- squashing these commits in a single commit
- parametrizing your test
However, those are minor comments and I don't think they should hold up this PR.
What do you mean by parameterizing the tests? |
In this case, I would take away the @pytest.mark.parametrize('which', [None, 'both', 'major', 'minor'])
def test_autofmt_xdate(which):
date = ['3 Jan 2013', '4 Jan 2013', '5 Ja....
... |
ab695ed
to
28d0f00
Compare
lib/matplotlib/tests/test_figure.py
Outdated
@@ -234,3 +237,38 @@ def test_figaspect(): | |||
assert h / w == 0.5 | |||
w, h = plt.figaspect(np.zeros((2, 2))) | |||
assert h / w == 1 | |||
|
|||
@pytest.mark.parametrize('which', [None, 'both', 'major', 'minor']) |
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.
pep8 will want another blank line here
28d0f00
to
0bfb832
Compare
Can someone help me here? All tests are passing locally. |
Travis failure looks like it's just a flaky test unrelated to your PR. Looks like the Appveyor build is old enough that it was suffering from systematic failures. |
@@ -0,0 +1 @@ | |||
The autofmt_xdate of the figure.Figure class previously formatted only major tick labels but now formats both minor and major tick labels by passing the argument "which = {None, 'minor', 'major', 'both'}". |
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 please use the template in README.rst
? That makes in very easy to combine each of these files when it comes time for a release.
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.
Didn't notice there was a template. Updated now.
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 file needs to be deleted now, as the next one covers it?
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.
Yup, forgot to delete that. Deleted now.
👍 except for the change to the docs. |
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.
LGTM implementation-wise; test could be tweaked a bit.
lib/matplotlib/tests/test_figure.py
Outdated
@pytest.mark.parametrize('which', [None, 'both', 'major', 'minor']) | ||
def test_autofmt_xdate(which): | ||
date = ['3 Jan 2013', '4 Jan 2013', '5 Jan 2013', '6 Jan 2013', | ||
'7 Jan 2013', '8 Jan 2013', '9 Jan 2013', '10 Jan 2013', '11 Jan 2013', |
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.
Align with the opening bracket.
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.
Done.
lib/matplotlib/tests/test_figure.py
Outdated
'12 Jan 2013', '13 Jan 2013', '14 Jan 2013'] | ||
|
||
time = ['16:44:00', '16:45:00', '16:46:00', '16:47:00', '16:48:00', | ||
'16:49:00', '16:51:00', '16:52:00', '16:53:00', '16:55:00', '16:56:00', |
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.
Here too.
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.
Done.
lib/matplotlib/tests/test_figure.py
Outdated
|
||
fig.autofmt_xdate(0.2, angle, 'right', which) | ||
|
||
if((which == 'both') or (which == 'major') or (which is None)): |
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 which in ('both', 'major', None):
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.
Changed.
lib/matplotlib/tests/test_figure.py
Outdated
for label in fig.axes[0].get_xticklabels(False, 'major'): | ||
assert (int(label.get_rotation()) == angle) | ||
|
||
if(which == 'both' or which == 'minor'): |
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 which in ('both', 'minor'):
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.
Changed.
lib/matplotlib/tests/test_figure.py
Outdated
|
||
if((which == 'both') or (which == 'major') or (which is None)): | ||
for label in fig.axes[0].get_xticklabels(False, 'major'): | ||
assert (int(label.get_rotation()) == angle) |
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.
Unnecessary parentheses.
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.
Removed.
lib/matplotlib/tests/test_figure.py
Outdated
|
||
if(which == 'both' or which == 'minor'): | ||
for label in fig.axes[0].get_xticklabels(True, 'minor'): | ||
assert (int(label.get_rotation()) == angle) |
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.
Unnecessary parentheses.
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.
Removed.
lib/matplotlib/figure.py
Outdated
@@ -1838,7 +1844,6 @@ def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1, | |||
|
|||
Right clicking cancels last input. | |||
|
|||
The buttons used for the various actions (adding points, removing |
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.
Why is this removed?
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.
Thanks for pointing that out, it was probably a mistake on my part.
lib/matplotlib/figure.py
Outdated
The horizontal alignment of the xticklabels | ||
|
||
which : {None, 'major', 'minor', 'both'} | ||
Selects which ticklabels to rotate |
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 should indicate what the default (None
) means; both, neither?
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.
Updated.
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.
Dunno if you want to squash, but LGTM.
Missed the earlier discussion about where to put the test and the curious fact that this is a figure method, not an axes method...
@patniharshit thanks for sticking with us! I fixed a minor pep8 thing. I'll wait for the CI to wrap up on that commit and then I'll merge. |
@patniharshit thanks again -- merged! |
refs #8128
Review required.
Also help needed in writing the test. Firstly I am not sure where to write the test, because a quick search in test_figure.py did not return any tests related to autofmt_xdate.