From: John H. <jdh...@ac...> - 2006-09-15 16:42:57
|
>>>>> "Brinley," == Brinley, Chris <Chr...@or...> writes: Chris> Hi, I am having trouble getting a variation of the Chris> tutorial plot_date() to work. I get the classic: Chris> RuntimeError: xdata and ydata must be the same length. Hmm, didn't know this had achieved classic status.... Chris> The tutorial on the matplotlib site shows how to plot Chris> dates using whole days. I am plotting using multiple Chris> days showing each minute of the day. Chris> Before I run plot_date I setup to datetime vars and Chris> subtract them to get the timedelta so.. timedelta = Chris> enddate - startdate. Chris> I then use drange(startdate, enddate, timedelta) This doesn't look right, since your delta equals the entire range. Usually you want your delta to be smaller. Chris> I pass this range into the plot_date function with my y Chris> axis data, which I have confirmed is numeric and the Chris> same number of entries as the number of datetimes I want Chris> to plot. Maybe you made a mistake here? It sometimes happens when working interactively that you add some bad data to a plot, realize your mistake, then add good data, but still see the error. When this happens, it is usually because your "hold" state is on and the previous data is still in your plot. You can clear the figure with fig.clf() If you are still having a problem, post a complete example that we can run. Chris> Clearly I am incorrectly telling plotlib the intervals Chris> of time I want to plot. What is the best way to plot out Chris> an interday chart that has ticks for each min? from matplotlib.dates import MinuteLocator ... # every minute ax.xaxis.set_major_locator(MinuteLocator()) # or every 5 minutes ax.xaxis.set_major_locator(MinuteLocator(nx.arange(0,61,5))) You'll probably also want to set the Formatter -- see the user's guide chapter on tick locating and formatting and also http://matplotlib.sf.net/matplotlib.ticker.html http://matplotlib.sf.net/matplotlib.dates.html and these examples mpl/examples> grep -l Locator *.py dashtick.py date_demo1.py date_demo2.py date_demo_convert.py date_demo_rrule.py finance_demo.py major_minor_demo1.py major_minor_demo2.py stock_demo.py |