Skip to content

Commit 06195c3

Browse files
committed
fix for issue matplotlib#135. Workaround for rounding problems
1 parent 1ae1b22 commit 06195c3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/matplotlib/dates.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,15 @@ def drange(dstart, dend, delta):
299299
delta.microseconds/MUSECONDS_PER_DAY)
300300
f1 = _to_ordinalf(dstart)
301301
f2 = _to_ordinalf(dend)
302-
return np.arange(f1, f2, step)
303-
304-
302+
303+
num = int(np.ceil((f2-f1)/step)) #calculate the difference between dend and dstart in times of delta
304+
dinterval_end = dstart + num*delta #calculate end of the interval which will be generated
305+
if dinterval_end >= dend: #ensure, that an half open interval will be generated [dstart, dend)
306+
dinterval_end -= delta #if the endpoint is greated than dend, just subtract one delta
307+
num -= 1
308+
309+
f2 = _to_ordinalf(dinterval_end) #new float-endpoint
310+
return np.linspace(f1, f2, num+1)
305311

306312
### date tickers and formatters ###
307313

0 commit comments

Comments
 (0)