python - Matplotlib axis time formatter -


i have logarithmic axis time in seconds on labels

10^1 sec, 10^2 sec, 10^3 sec, 10^4 sec ... 

like similarily possible engformatter want have axis ticks , labels in seconds, minutes, hours, days, this:

0 sec, 30 sec, 1 min, 30 min, 1 hour, 12 hour, 1 day ... 

how axis ticks , labels that?

i able create axis wanted

plot

with code:

def to_time(x, position):     x = float(x)     timeunit = 'sec'     if x >= 60:         x = x/60         timeunit = 'min'         if x >= 60:             x = x/60             timeunit = 'h'     # can modify actual string here     string = '%.0f%s' % (x,timeunit)     return string  #... plots here  ax.set_yscale('log') tickermajor = loglocator(base=60) tickerminor = loglocator(base=60, subs=[10,20,30,40,50]) ticklabels = funcformatter(to_time) ax.yaxis.set_major_locator(tickermajor) ax.yaxis.set_minor_locator(tickerminor) ax.yaxis.set_major_formatter(ticklabels) 

hope helps somebody. works sec, min , hours, not days, months etc no longer reachable log60.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -