|
96 | 96 | <../gallery/ticks_and_spines/date_demo_rrule.html>`_.
|
97 | 97 |
|
98 | 98 | * :class:`AutoDateLocator`: On autoscale, this class picks the best
|
99 |
| - :class:`DateLocator` to set the view limits and the tick |
| 99 | + :class:`DateLocator` (e.g., :class:`RRuleLocator`) |
| 100 | + to set the view limits and the tick |
100 | 101 | locations. If called with ``interval_multiples=True`` it will
|
101 | 102 | make ticks line up with sensible multiples of the tick intervals. E.g.
|
102 | 103 | if the interval is 4 hours, it will pick hours 0, 4, 8, etc as ticks.
|
@@ -290,22 +291,21 @@ def _from_ordinalf(x, tz=None):
|
290 | 291 |
|
291 | 292 | remainder = float(x) - ix
|
292 | 293 |
|
293 |
| - # Round to the nearest microsecond. |
294 |
| - dt += datetime.timedelta( |
295 |
| - microseconds=int(round(remainder * MUSECONDS_PER_DAY))) |
296 |
| - |
297 |
| - # Compensate for rounding errors |
298 |
| - if x > 30 * 365: |
299 |
| - # Since the input date `x` float is unable to preserve |
300 |
| - # microsecond precision of time representation in non-antique |
301 |
| - # years, the resulting datetime is rounded to the nearest |
302 |
| - # multiple of `musec_prec`. A value of 20 is appropriate for |
303 |
| - # current dates. |
304 |
| - musec_prec = 20 |
305 |
| - musec = datetime.timedelta( |
306 |
| - microseconds=int(round( |
307 |
| - dt.microsecond / float(musec_prec)) * musec_prec)) |
308 |
| - dt = dt.replace(microsecond=0) + musec |
| 294 | + # Since the input date `x` float is unable to preserve microsecond |
| 295 | + # precision of time representation in non-antique years, the |
| 296 | + # resulting datetime is rounded to the nearest multiple of |
| 297 | + # `musec_prec`. A value of 20 is appropriate for current dates. |
| 298 | + musec_prec = 20 |
| 299 | + remainder_musec = int(round(remainder * MUSECONDS_PER_DAY / |
| 300 | + float(musec_prec)) * musec_prec) |
| 301 | + |
| 302 | + # For people trying to plot with full microsecond precision, enable |
| 303 | + # an early-year workaround |
| 304 | + if x < 30 * 365: |
| 305 | + remainder_musec = int(round(remainder * MUSECONDS_PER_DAY)) |
| 306 | + |
| 307 | + # add hours, minutes, seconds, microseconds |
| 308 | + dt += datetime.timedelta(microseconds=remainder_musec) |
309 | 309 |
|
310 | 310 | return dt.astimezone(tz)
|
311 | 311 |
|
|
0 commit comments