I am plotting time-series 1-minute cadence data for specific multiple-day validation periods.

Sometimes the data have a gap between the start of the validation period and the start of the data. Attached is a stand-alone Python script that demonstrates the problem, along with the plot that the script produces.

April 20 is the start of the validation period. I want 04-20 to appear at the plot origin. This does not happen unless either the model or observed dictionary contain a key/value pair for 1998,4,20,0. I tried adding datetime(1998,4,20,0):None to one or both dictionaries, but it is ignored.

Also the minor tick marks do not look right, especially the ones just to the right of each x-axis label.

Do you have any suggestions?

Thanks,
Ann

I am working on a Windows PC; O/S is Windows XP Professional, Version 2002, Service Pack 3. I am running matplotlib, version '0.99.0' which I obtained from the matplotlib Sourceforge site.
I have not customized matplotlibrc.
I am running python version 2.6.2.
Attached is output.txt, the result of running my script with a verbose-helpful

<<inline: test_plot.png>>

import pylab
from datetime import datetime
from matplotlib.dates import date2num,DayLocator,HourLocator,DateFormatter
from matplotlib.pyplot import close
def test_plot():
   '''
   test_plot.py
   Test code: How to get x-axis labeling to start at the plot origin?
    
   USE
      test_plot()
   '''

   
model={datetime(1998,4,20,1):19.7,datetime(1998,4,21):42.2,datetime(1998,4,22):8.4,datetime(1998,4,23):28.2,datetime(1998,4,24):21.5}
   
observed={datetime(1998,4,20,1):20.1,datetime(1998,4,21):40.2,datetime(1998,4,22):10.4,datetime(1998,4,23):30.2,datetime(1998,4,24):22.5}

   observed_keys=observed.keys()
   observed_keys.sort()
   observed_values=[]
   for timetag in observed_keys:
      observed_values.append(observed[timetag])

   model_keys=model.keys()
   model_keys.sort()
   model_values=[]
   for timetag in model_keys:
      model_values.append(model[timetag])

   fig=pylab.figure(facecolor='w')
   
   ax=fig.add_subplot(111)

   ax.plot_date(date2num(observed_keys),observed_values,'-',color='black')
   ax.plot_date(date2num(model_keys),model_values,'-',color='red')
   days=DayLocator() #major ticks will be on each day of the month
   hours=HourLocator(interval=6) #minor ticks will be every 6 hours 
   daysFmt=DateFormatter('%m-%d') #x-axis major tick labels for plot


   # format the ticks
   ax.xaxis.set_major_locator(days)       # major x-axis ticks
   ax.xaxis.set_major_formatter(daysFmt)  #x-axis major tick labels
   ax.xaxis.set_minor_locator(hours)      #minor x-axis ticks

   ax.fmt_xdata = DateFormatter('%m-%d')
   fig.autofmt_xdate(rotation=-30, ha='left')  #rotate and right align the 
xaxis labels

   pylab.legend(('obs','model'),labelspacing = 0.005,loc='upper right')

   pylab.show()
   raw_input("press return to continue")
   close()  #close the figure.
   return 1

if __name__ == '__main__':
   test_plot()

                              
$HOME=C:\Documents and Settings\ann.newman
CONFIGDIR=C:\Documents and Settings\ann.newman\.matplotlib
matplotlib data path C:\Python26\lib\site-packages\matplotlib\mpl-data
loaded rc file C:\Python26\lib\site-packages\matplotlib\mpl-data\matplotlibrc
matplotlib version 0.99.0
verbose.level helpful
interactive is False
units is False
platform is win32
Using fontManager instance from C:\Documents and 
Settings\ann.newman\.matplotlib\fontList.cache
backend TkAgg version 8.5
findfont: Matching 
:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium
 to Bitstream Vera Sans 
(C:\Python26\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf) with 
score of 0.000000
findfont: Matching 
:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=large
 to Bitstream Vera Sans 
(C:\Python26\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf) with 
score of 0.000000
press return to continue

<<attachment: Ann_Newman.vcf>>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to