Closed
Description
Bug report
Bug summary
- If your data has a certain number of days, around 130, AutoDateLocator plots ticks at the 1st and 22nd of the month (if
interval_multiples=True
) - This looks odd, I would expect more evenly spaced ticks
Code for reproduction
import datetime as dt
import matplotlib.pyplot as plt
#plot a range of 130 sequential dates
start_date = dt.datetime(2000,1,1)
length = 130
dates = [start_date + dt.timedelta(x) for x in range(length)]
data = [1 for x in range(length)]
fig, ax = plt.subplots()
ax.plot(dates, data)
#prevent overlapping labels
ax.tick_params(axis='x', labelrotation=90)
Expected outcome
- More evenly spaced ticks
Possible fix
- AutoDateLocator has a block that sets the byranges sent to the RRulelocator if
interval_multiples
isTrue
- It has some special cases, for intervals of 14 or 7 days
- Adding
or (interval == 21)
treats the 21-day interval the same as the 14-day (see below) - (However, this may sometimes result in a date plotted at the end of the axis. I do not know what causes this, it may have something to do with autoscaling?)
if self._byranges[i] and self.interval_multiples:
byranges[i] = self._byranges[i][::interval]
if i in (DAILY, WEEKLY):
#--------------------------------------------------------------------------
# adding the 21-day interval to this if statement forces the first and 15th
if (interval == 14) or (interval == 21):
#--------------------------------------------------------------------------
# just make first and 15th. Avoids 30th.
byranges[i] = [1, 15]
elif interval == 7:
byranges[i] = [1, 8, 15, 22]
Matplotlib version
- Operating system: Windows 10 Home
- Matplotlib version: 3.1.3
- Matplotlib backend: module://ipykernel.pylab.backend_inline
- Python version: 3.7.6
- Jupyter version: 6.0.3
- Installed Python and Matplotlib using the Windows Anaconda installer
Metadata
Metadata
Assignees
Labels
No labels