Hi,

I am having trouble to customize the format of date axis tick labels. Below
is a snippet to demonstrate my problem:
#------------------------------------- code
----------------------------------------------------
# Make an example plot.
fig = figure()
tsta = num2epoch(date2num(datetime.datetime.now()))
tarr = tsta + arange(0, 60*60*0.5, 0.1)                # half hour, dt =
0.1 sec
x = np.array(num2date(epoch2num(tarr)))
nt = len(tarr)
y = randn(nt)

ax = fig.add_subplot(111)
ax.plot(x, y)
fig.canvas.draw()

# Make a formatter instance.
locator = mpl.dates.AutoDateLocator()
formatter = mpl.dates.AutoDateFormatter(locator)

# Customize the scaling.
formatter.scaled = {
    365.0 : '%Y',               # view interval > 356 days
    30. : '%b %Y',             # view interval > 30 days but less than 365
days
    1.0 : '%b %d',             # view interval > 1 day but less than 30 days
    1./24. : '%H:%M',        # view interval > 1 hour but less than 24 hours
    1./24./60. : '%M:%S',  # view interval > 1 min but less than 1 hour
    1./24./60./60. : '%S',   # view interval < 1 min
}

# Apply the formatter and redraw the plot.
ax.get_xaxis().set_major_formatter(formatter)
fig.canvas.draw()
#---------------------------------- end of code
-------------------------------------------------

I listed my expectation about the new scaling above. However, what I got
was simply '%Y' after I applied the formatter. So, how can I make the new
formatter work, please? Thank you very much.

Jianbao
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to