Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0339042

Browse files
authored
Merge pull request matplotlib#17269 from leolchat/patch-1
Fix ConciseDateFormatter when plotting a range included in a second
2 parents d53b16c + 2c27a02 commit 0339042

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/matplotlib/dates.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,10 @@ def format_ticks(self, values):
796796
for level in range(5, -1, -1):
797797
if len(np.unique(tickdate[:, level])) > 1:
798798
break
799+
elif level == 0:
800+
# all tickdate are the same, so only micros might be different
801+
# set to the most precise (6: microseconds doesn't exist...)
802+
level = 5
799803

800804
# level is the basic level we will label at.
801805
# now loop through and decide the actual ticklabels

lib/matplotlib/tests/test_dates.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,17 @@ def _create_auto_date_locator(date1, date2):
449449
assert list(map(str, mdates.num2date(locator()))) == expected
450450

451451

452+
def test_concise_formatter_subsecond():
453+
locator = mdates.AutoDateLocator(interval_multiples=True)
454+
formatter = mdates.ConciseDateFormatter(locator)
455+
year_1996 = 9861.0
456+
strings = formatter.format_ticks([
457+
year_1996,
458+
year_1996 + 500 / mdates.MUSECONDS_PER_DAY,
459+
year_1996 + 900 / mdates.MUSECONDS_PER_DAY])
460+
assert strings == ['00:00', '00.0005', '00.0009']
461+
462+
452463
def test_concise_formatter():
453464
def _create_auto_date_locator(date1, date2):
454465
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)