-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Bug : (minor) time axis labels show "%f" instead of microseconds for years up to 1900 #3179
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
Good spot @azjps, and thanks for making it easy to reproduce. Are you interested in having a go at implementing a fix for this? |
Sure :) It seems to me that these three lines in timetuple = dt.timetuple()
s1 = time.strftime(fmt, (year,) + timetuple[1:])
s2 = time.strftime(fmt, (year + 28,) + timetuple[1:]) could be replaced by s1 = dt.replace(year=year).strftime(fmt)
s2 = dt.replace(year=year+28).strftime(fmt) although someone should check that setting to this year in a |
Add a simple test for DateFormatter. closes matplotlib#3179 Change-Id: Idff9d06cbc6dc00a3cb8dcf113983d82dbdd3fde
It also fails to replace %y or %x correctly, since its strftime implementation replaces only 4-digit years. I added a boolean flag DateFormatter.replace_directives_before_1900: - If False, strftime uses the old implementation, which will not replace %f and which will replace incorrect values for %y and %x. - If True, strftime will first try a few regular expressions to replace %y/%x/%f with the appropriate datetime values. I'm not positive this covers all cases but I don't know of any cases where this fails right now. Add a simple test for DateFormatter with and without this flag. closes matplotlib#3179 Change-Id: Idff9d06cbc6dc00a3cb8dcf113983d82dbdd3fde
It also fails to replace %y or %x correctly, since its strftime implementation replaces only 4-digit years. Instead, we now use a regular expression to replace %f with the microsecond value. (We could also be tricky and call strftime again with the original datetime object ..) We also make substitutions for both 2-digit and 4-digit years, which for example are displayed by %y, %Y, and %x. Minor point: in time.h, strftime will not use padding for %y and %Y but will use zero-padding for %x. Since this is unlikely to ever be a cause of concern and isn't documented anywhere afaik, I've used zero-padding for all three. (Certainly it's preferable to just printing the wrong year!) Add tests and (maybe excessively long?) comments. closes matplotlib#3179 Change-Id: Idff9d06cbc6dc00a3cb8dcf113983d82dbdd3fde
It also fails to replace %y or %x correctly, since its strftime implementation replaces only 4-digit years. Instead, we now use a regular expression to replace %f with the microsecond value. (We could also be tricky and call strftime again with the original datetime object ..) We also make substitutions for both 2-digit and 4-digit years, which for example are displayed by %y, %Y, and %x. Minor point: in time.h, strftime will not use padding for %y and %Y but will use zero-padding for %x. Since this is unlikely to ever be a cause of concern and isn't documented anywhere afaik, I've used zero-padding for all three. (Certainly it's preferable to just printing the wrong year!) Add tests and (maybe excessively long?) comments. closes matplotlib#3179 Change-Id: Idff9d06cbc6dc00a3cb8dcf113983d82dbdd3fde
When plotting with a timestamp-based axis with datetimes of years
<= 1900
, upon zooming into sub-second scales, the default axis label date formatter shows "%f" instead of microseconds.This is since
timetuple
doesn't carry microsecond data. Minor in nature (was using a sentinel date of 1900 without realizing matplotlib would handle it specially) but I figured I would point it out.The text was updated successfully, but these errors were encountered: