Use ConciseDateFormatter which is meant to improve the strings chosen for the ticklabels, and to minimize the strings used in those tick labels as much as possible. https://matplotlib.org/stable/gallery/ticks/date_concise_formatter.html Parameters ---------- ax : Axes
(ax: Axes, axis: Literal["x", "y", "z"] = "x")
| 1844 | |
| 1845 | |
| 1846 | def _set_concise_date(ax: Axes, axis: Literal["x", "y", "z"] = "x") -> None: |
| 1847 | """ |
| 1848 | Use ConciseDateFormatter which is meant to improve the |
| 1849 | strings chosen for the ticklabels, and to minimize the |
| 1850 | strings used in those tick labels as much as possible. |
| 1851 | |
| 1852 | https://matplotlib.org/stable/gallery/ticks/date_concise_formatter.html |
| 1853 | |
| 1854 | Parameters |
| 1855 | ---------- |
| 1856 | ax : Axes |
| 1857 | Figure axes. |
| 1858 | axis : Literal["x", "y", "z"], optional |
| 1859 | Which axis to make concise. The default is "x". |
| 1860 | """ |
| 1861 | import matplotlib.dates as mdates |
| 1862 | |
| 1863 | locator = mdates.AutoDateLocator() |
| 1864 | formatter = mdates.ConciseDateFormatter(locator) |
| 1865 | _axis = getattr(ax, f"{axis}axis") |
| 1866 | _axis.set_major_locator(locator) |
| 1867 | _axis.set_major_formatter(formatter) |
no outgoing calls
no test coverage detected
searching dependent graphs…