It does?! Do you mean that this is done automatically? Can you show me an example of this using only the time module (since I use python2.2, dont have datetime)? I thought that I had to manually set things up and tell matplotlib whether to use YearLocator, MonthLocator, etc.. via calls to: axes.xaxis.set_minor_locator(), axes.xaxis.set_major_locator(), axes.xaxis.set_major_formatter().
In other words for every plot, check the time range of my data, figure out how many ticks I want, and decide whether to use months, days, hours, etc...
In fact, because I was getting some inconsistent results with using the above, I decided that for the most part (excluding a few special cases), I would print the time ticks myself 'manually'. The script below shows what I mean.
On the other note, regarding the weird scaling that I talked about (and showed pretty pics for) in my last mail, I finally put together a small script that exposes the problem. It is a bit rough because I ripped bits and pieces from here and there, but shows the issue. Use the 'wantBadPlot' and 'wantStandardDateTics' to see how things go wrong.
from matplotlib.dates import EpochConverter
from matplotlib.matlab import *
from matplotlib.ticker import FuncFormatter, NullLocator, MinuteLocator, DayLocator, HourLocator, MultipleLocator, DateFormatter
ax = subplot(111)
p1=plot_date(time1, data1, None, '-', color='r')
p2=plot_date(time2, data2, None, '-', color='b')
#Manually display dates for tick-labels. Technically could use plot() and
#get the same result.
tickList=[item for item in list(arange(then, now, deltaTickSec))]
def tickString(x, pos):
return time.strftime("%H:%M:%S", time.localtime(x))
formatter = FuncFormatter(tickString)
#This will fix the problem!!
legend((p1, p2), ('small data set (%d)' % p1Size, 'large data set (%d)' % p2Size))
Finally, just want to verify (form my last email) that in axes.py:
"Get the y axis range [ymin, ymax]"
should intervax() be intervaly()??
Peter Groszkowski Gemini Observatory
Tel: +1 808 974-2509 670 N. A'ohoku Place
Fax: +1 808 935-9235 Hilo, Hawai'i 96720, USA
John Hunter wrote:
> I found another issue with plot_date. Dont have a simple
> example yet, and hope that this is something 'obvious' and
> I don't have to bother.
There is clearly something wrong with the autoscale function of one of
the date tick locators. It would help to know which one. plot_date
looks at the range of your date data and tries to pick the appropriate
date tick locator based on that range (ie a YearLocator, MonthLocator,
MinuteLocator, etc). If I knew which tick locator was behaving badly,
it would help me fix the problem.
after the call to plot_date, and let me know which locator it is, I
can probably figure out where the problem is. To simplify, don't
explicitly set the date xlim range when you do this.
On a side note, in your example code you call
I assume you did this to narrow down the possible causes of problems.
As you know, this is the call that ax.set_xlim makes under the hood.
But in general, it's safest to stick to the axes API, ie, call
since this interface is guaranteed to be stable.
This SF.Net email is sponsored by the new InstallShield X.
From Windows to Linux, servers to mobile, InstallShield X is the
one installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
Matplotlib-users mailing list