Goyo wrote: > Hi all, > > I'm plotting time series and using a custom format for x tick labels > because I want to see both date and time. But calling xlim makes the > default format return -- only dates or only times, it depends on the > displayed interval. > > I can get my preferred format back by calling set_major_formatter again, > but this is inconvenient for interactive use. > > I wonder if there is a better way for changing x limits while keeping > tick labels format unchanged. > > I'm using matplotlib 0.98.3 > > Thanks > > Goyo > > > Sample code -- you need a combination of python shell and matplotlib GUI > which allows for interactive use in order to get this working as > expected: > > ---------------------------------------- > > from matplotlib import pyplot > from matplotlib import dates > from datetime import datetime, timedelta > from numpy import random > > pyplot.ion() > > # create data > dstart = datetime(2008, 1, 1, 0, 0) > dend = datetime(2008, 1, 5, 23, 50) > delta = timedelta(minutes=10) > x = dates.drange(dstart, dend, delta) > y = random.random_sample(len(x)) > > # plot data > pyplot.plot(x, y) > > # format x tick labels > axis = pyplot.gca() > fig = pyplot.gcf() > axis.xaxis.set_major_formatter(dates.DateFormatter('%Y-%b-%d %H:%M')) > fig.autofmt_xdate() > > # draw the figure > pyplot.draw() > > -------------------------------------- > > Look at the tick labels, they show both date and time even if you zoom > and pan using the GUI. > > Now if I want to look at the second day: > > dstart = datetime(2008, 1, 1, 0, 0) > dend = datetime(2008, 1, 1, 23, 50) > pyplot.xlim(dstart, dend) > > And the format has changed.
I don't see this problem using ipython -pylab with mpl from svn on linux, gtkagg backend. What version, backend, and platform are you using? Eric ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users