Skip to content

Commit 784e1d2

Browse files
committed
Switch to constrained layout and ConciseDateFormatter.
1 parent 5caf399 commit 784e1d2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

doc/users/next_whats_new/imshow_extent_units.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ can now be expressed with units.
88

99
import matplotlib.pyplot as plt
1010
import numpy as np
11-
from matplotlib.dates import HourLocator, DateFormatter
11+
from matplotlib.dates import HourLocator, ConciseDateFormatter
1212
from matplotlib.ticker import AutoMinorLocator
1313

1414
fig, ax = plt.subplots(layout='constrained')
@@ -19,8 +19,14 @@ can now be expressed with units.
1919

2020
ax.imshow(arr, origin='lower', extent=[1, 11, date_first, date_last])
2121

22-
ax.yaxis.set_major_formatter(DateFormatter('%d/%m/%y:- %H00hours'))
23-
ax.yaxis.set_major_locator(HourLocator(byhour=[0, 12, 24]))
22+
locator = HourLocator(byhour=[0, 12, 24])
23+
ax.yaxis.set_major_formatter(
24+
ConciseDateFormatter(
25+
locator, show_offset=False,
26+
zero_formats=['', '%Y', '%b', '%b-%d %H:%M', '%H:%M', '%H:%M']
27+
)
28+
)
29+
ax.yaxis.set_major_locator(locator)
2430
ax.yaxis.set_minor_locator(AutoMinorLocator())
2531

2632
plt.show()

0 commit comments

Comments
 (0)