-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
General poor default formatting of datetimes on plot x-axis #9978
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
Comments
Completely agree. See #9801 for a partial fix and some discussion. The formatting is a bit of a bigger project, but at least #9801 will force ticks to line up with reasonable places. If you want to work around for the Auto tick locations, you will find the following improves things a good bit. locator = AutoDateLocator(interval_multiples=True)
ax.xaxis.set_locator(locator) You can also set |
The Hopefully this catches the eye if anyone is currently working on this. If not, I may give it a shot. |
I was goiong to plow ahead in #9801, but its a breaking change that'll require some buy-in. |
ok, that would be great. Thanks.
|
Well, if you want to try the above, you should definitely go for it. But... I think you have a pretty specific case in mind that won't work for the default which can span centuries to milli-seconds. Checking for overlaps is pretty tough. Better just to rotate the ticks... |
Agreed that it would be difficult to make a one-size-fits-all default, but I think it's worth trying, so happy to give it a shot. I just got this out through default behaviour... To be fair, the datetime format is highly logical, but so not how we typically use datetime formats.. (I guess it would be nice if humans could naturally parse so logically) |
Is 12-11 the date? See, this is why its so subjective. My plan was to strip the date except when the day rolls over. Otherwise, I figure the user can put it in the xlabel if they need the date noted on the plot. |
I think this may be where it's worth learning from other plotting platforms.. matlab, plotly, gadfly etc. |
And indeed, 12-11 is the date. I think the fact you have to ask illustrates the issue well! Just to clarify, the plot I got out above was from default behaviour. That might not've been clear |
FWIW, checking for overlapping of the tick labels may be out of the scope of a PR that would try to get better defaults for datetime labels. IIRC, it is a general “issue” of Matplotlib in the sense that (I think that ) it is difficult to know the effective size of the text boxes before rendering the figure and that for this reason the number of ticks that is used is actually simply based on heuristics. The problem is that those heuristics are likely to have been designed for “rather general” tick labels (i.e. a few digits I guess) while the datetime tick labels are usually significantly longer than numerical ones and thus more prone to overlapping. But it is quite easy to trigger a situation where even numerical tick labels with long formatting overlap as well. |
Yeah, the heuristic for AutoLocator is 3-em. It usually works pretty well. |
See #10841 |
OK, I'm going to close this because #10841 is now available. Its not default (yet ;-)), but I think closes this PR. Feel free to discuss here if you disagree. |
General poor default formatting of datetimes on plot x-axes
I find the default datetime formatting on the basic plot function to be very suboptimal, and often causes overlapping labels.

Some factors that I think are worth addressing:
It is obviously possible to improve date formatting through tick formatting, especially the use of major and minor tick formatting and positioning, but I find this very frustrating to do each time, and would appreciate an improved default functionality.
My suggestion would be to move the date to the major ticks, and time to minor ticks, with time only specified in the commonly known iso formats: "hh:mm" and "hh:mm:ss", and date set to the ISO format: "YYYY-MM-DD".
Or a minimal change would be to change the current functionality to default to "hh:mm" rather than "DD hh:mm"
The text was updated successfully, but these errors were encountered: