python - Matplotlib date ticker - exceeds Locator.MAXTICKS error for no apparent reason -


when plot datapoints vs time, spanning on 2 days, , set datelocator 0 , 30 minutes. major tick each half hour, matplotlib throws error. consider example:

from datetime import datetime import matplotlib.pyplot plt import matplotlib.dates mdates  datapoints = 3600*24*2   #2 days, 1 datapoint/second data = range(datapoints)  #anydata timestamps = [ datetime.fromtimestamp(t) t in range(datapoints) ]  fig = plt.figure() ax = fig.add_subplot(1,1,1)    ax.xaxis.set_major_locator(mdates.minutelocator(byminute=[0,30]))  plt.plot(timestamps,data) plt.show() 

then following error:

runtimeerror: rrulelocator estimated generate 2879 ticks 1970-01-01 01:00:00+00:00 1970-01-03 00:59:59+00:00: exceeds locator.maxticks * 2 (2000)

2879 ticks amount of minutes in timespan, meaning estimate based on 1 tick every minute. locator should yield 1 tick every 30 minutes (2 ticks per hour in 48 hour = 96 ticks). why estimate , real value far eachother?

a workaround raise maxticks value:

locator = mdates.minutelocator(byminute=[0,30]) locator.maxticks = 1500 ax.xaxis.set_major_locator(locator) 

that works , graph nicely shows. should not needed right? why error occuring in first place? using datelocator wronly?

the real issue rrulelocator assumes underlying rrule instance's interval variable have been updated when byminute set , interval isn't passed in on initialization (it defaults 1). in fact, interval ignored in rrule (with small exceptions w.r.t. if filtered set or not) when byxxx (hour/minute/second etc) set!

instead of overriding maxticks, better change code include interval on minutelocator 30 well. won't change how final image drawn per above (unless using filtered).

ax.xaxis.set_major_locator(mdates.minutelocator(byminute=[0,30], interval=30)) 

granted while workaround well, estimation check in rrulelocator's tick_values can cleaned include set in byxxx variables (although messy).


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - Microsoft Access OledbDataReader read values error -