FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Backport PR #22871 on branch v3.5.x (Fix year offset not always being added) by meeseeksmachine · Pull Request #22878 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 4 additions & 2 deletions lib/matplotlib/dates.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,10 @@ def format_ticks(self, values):
# mostly 0: years, 1: months, 2: days,
# 3: hours, 4: minutes, 5: seconds, 6: microseconds
for level in range(5, -1, -1):
if len(np.unique(tickdate[:, level])) > 1:
if level < 2:
unique = np.unique(tickdate[:, level])
if len(unique) > 1:
# if 1 is included in unique, the year is shown in ticks
if level < 2 and np.any(unique == 1):
show_offset = False
break
elif level == 0:
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/tests/test_dates.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ def test_offset_changes():
ax.set_xlim(d1, d1 + datetime.timedelta(weeks=3))
fig.draw_without_rendering()
assert formatter.get_offset() == '1997-Jan'
ax.set_xlim(d1 + datetime.timedelta(weeks=7),
d1 + datetime.timedelta(weeks=30))
fig.draw_without_rendering()
assert formatter.get_offset() == '1997'
ax.set_xlim(d1, d1 + datetime.timedelta(weeks=520))
fig.draw_without_rendering()
assert formatter.get_offset() == ''
Expand Down

Back | FazBrowse Home | New Git URL