From: questions a. <que...@gm...> - 2012-04-12 01:46:12
|
Hi matplotlib list, I am having trouble applying mdates in matplotlib. I am not sure how to recognise that x-axis are dates like 20110101, 20110102, 20110103 etc. Any feedback will be greatly appreciated! below is the code I have so far: import numpy as np import matplotlib.pyplot as plt from numpy import ma as MA from mpl_toolkits.basemap import Basemap import os import glob import matplotlib.dates as mdates MainFolder=r"E:/Rainfall/rainfall-2011/test/" OutputFolder=r"E:/test_out/" rmax=[] monthyear=[] for (path, dirs, files) in os.walk(MainFolder): path=path+'/' for fname in files: if fname.endswith('.txt'): filename=path+fname fileName, fileExtension=os.path.splitext(fname) test=fileName.strip('r') test=str(test) monthyear.append(test) f=np.genfromtxt(filename, skip_header=6) dailymax=f.max() rmax.append(dailymax) print rmax print monthyear x=monthyear y=rmax fig, ax=plt.subplots(1) plt.plot(x,y) fig.autofmt_xdate() ax.fmt_xdata=mdates.DateFormatter('%Y%m%d') plt.ylabel("Precipitation") plt.title("Max daily Precipition Vic") plt.savefig(OutputFolder+"MaxdailyPrecip.png") plt.show() |