-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: Change default Autodatelocator *interval_multiples* #9801
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
As a further suggestion for discussion, I'd also consider changing the interval for 14 days from a strict 14 days to first of month, 15th of month. We could consider regularizing all the daily intervals to be sure they fall on month boundaries. The above fails the obvious image comparison tests... |
Is their appetite for changing the default formatters as well, particularly for dates: I'd strip repeated entries. i.e. for "Feb 01", "Feb 08", "Feb 15", I'd strip "Feb" from the second two labels. i.e. only show month name when day == 1. Similarly, only show years when month == 1 (and day==1). That would make tick labels much more compact. To make that work properly, the rcParams for the date formaters (i.e. |
I am open to this so long as there is clear and easy instructions on how to get old behavior back. |
I'll work on this. I was also thinking a tutorial on how to label axes would be useful. I think that info is in a bunch of examples all over the place, but not explained systematically. @tacaswell I only hesitate because I keep hearing rumours that you have a documentation plan. If so, I can wait for that, and help contribute to that. |
There is a plan to make a plan. In any outcome, the more content we have up front the less we have to write later (even if we re-organize or re-word it a bit). If matching the current API is too annoying, making a new formatter / locator (but not using them by default yet) is a reasonable course of action as well. |
07eeb57
to
1d5fa6e
Compare
OK, this PR makes |
be9c155
to
3356826
Compare
lib/matplotlib/dates.py
Outdated
byranges[i] = self._byranges[i][::interval] | ||
if i == 2 and interval == 14: | ||
# special case for monthday: Just tick 1 and 15: | ||
byranges[i] = range(1, 16, 14) |
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.
Could this not simply be [1, 15] to make it more clear?
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!
3356826
to
e090ff4
Compare
lib/matplotlib/tests/test_dates.py
Outdated
@@ -319,7 +319,8 @@ def test_empty_date_with_year_formatter(): | |||
|
|||
def test_auto_date_locator(): | |||
def _create_auto_date_locator(date1, date2): | |||
locator = mdates.AutoDateLocator() | |||
# we prob. should eventually have a test w/ interval_multiples=True |
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 comment is out of date.
setup.cfg.template
Outdated
@@ -13,12 +13,12 @@ | |||
# set this to True. It will download and build a specific version of | |||
# FreeType, and then use that to build the ft2font extension. This | |||
# ensures that test images are exactly reproducible. | |||
#local_freetype = False | |||
local_freetype = True |
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 looks extraneous.
lib/matplotlib/dates.py
Outdated
@@ -1338,7 +1341,11 @@ def get_locator(self, dmin, dmax): | |||
self._freq = freq | |||
|
|||
if self._byranges[i] and self.interval_multiples: | |||
byranges[i] = self._byranges[i][::interval] | |||
print(self._byranges[i]) |
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.
print()
needs to go before merging.
lib/matplotlib/dates.py
Outdated
@@ -1234,6 +1234,9 @@ def __init__(self, tz=None, minticks=5, maxticks=None, | |||
MICROSECONDLY: [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, | |||
5000, 10000, 20000, 50000, 100000, 200000, 500000, | |||
1000000]} | |||
if interval_multiples: | |||
self.intervald[3] = [1, 2, 4, 7, 14, 21] |
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.
Instead of [3]
do you mean [DAILY]
?
I agree with the basic idea here of using "nice" values by default. It would be good to get this into 3.0. |
b755888
to
44c0bbb
Compare
Reviews addressed, squashed and rebased, API note added (that may need CI to test if it rendered correctly). |
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.
Looks good.
lib/matplotlib/dates.py
Outdated
@@ -1234,6 +1234,9 @@ def __init__(self, tz=None, minticks=5, maxticks=None, | |||
MICROSECONDLY: [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, | |||
5000, 10000, 20000, 50000, 100000, 200000, 500000, | |||
1000000]} | |||
if interval_multiples: | |||
self.intervald[DAILY] = [1, 2, 4, 7, 14, 21] |
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.
Perhaps just curiosity, but why have this substitution of 4 for 3 in this case, and not in general? And isn't 21 a rather strange option? It is inconsistent with the docstring.
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.
To clarify, the 21 option is present in the current code as well as in the line cited above, so the inconsistency predates your 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.
Yeah, I don't know why the 21 is in there. I left it in as possibly some weird edge case, but I don't see how it'd happen.
3 vs 4?
3: 1, 4,..., 28, 31, 1
4: 1, 5, ... 25, 29, 1
So except for Feb leap years it avoids an awkward cross-month transition.
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.
added a couple of comments...
This is ready for a second review.... Relatively simple change that I think makes the date locators much better... |
1e609db
to
7c994b8
Compare
Also make monthly byranges be 1 and 15
7c994b8
to
0337883
Compare
squashed... |
PR Summary
OK, AutoDateLocator returned "not-nice" tick labels:
So like a dummy, I went and tried to implement better ticks that snapped to the tick intervals (10 minutes in this case). Then this morning I reread the code and found that lo-and-behold, it has a flag for this (
interval_multiples=False
)I don't see the rationale behind the default being
interval_multiples=False
. Other than that it will break some existing tests, and its a breaking change. The resulting ticks look far better, and are much more amenable to panning. Tick locators are obscure enough that I never use them except in extremis, so expecting normal users to change options in them just to get something that looks somewhat rational is not putting our best foot forward.PR Checklist