2016-02-03 67 views
0

我想繪製3個子圖,第一個圖爲條形圖。當我這樣做時,x軸向左移動。我看到很奇怪的條形圖,看下面的圖。如果我通過''plot''改變''bar''比它的工作正常,但圖表是一條線而不是酒吧。製作包括條形圖的子圖

enter image description here

kwargs=dict(delimiter='\t',\ 
     skip_header=0,\ 
     missing_values='NaN',\ 
     converters={0:matplotlib.dates.strpdate2num('%d-%m-%Y %H:%M')},\ 
     dtype = float,\ 
     names=True,\ 
     ) 

storm_dis_cats = np.genfromtxt('C:\Users\ker\Documents\Discharge_data_Catsop_27-06-2014.txt',**kwargs) 

kwargs=dict(delimiter='\t',\ 
     skip_header=0,\ 
     missing_values='NaN',\ 
     converters={0:matplotlib.dates.strpdate2num('%d-%m-%Y %H:%M')},\ 
     dtype = float,\ 
     names=True,\ 
     ) 

storm_stage_cats = np.genfromtxt('C:\Users\ker\Documents\Stageheight_data_Catsop_27-06-2014.txt',**kwargs) 

kwargs=dict(delimiter='\t',\ 
     skip_header=0,\ 
     missing_values='NaN',\ 
     converters={0:matplotlib.dates.strpdate2num('%d-%m-%Y %H:%M')},\ 
     dtype = float,\ 
     names=True,\ 
     ) 

storm_rain_cats = np.genfromtxt('C:\Users\ker\Documents\Rainfall_data_Catsop_27-06-2014.txt',**kwargs) 

discharge = storm_dis_cats['discharge'] 
date = storm_stage_cats['date'] 
stage = storm_stage_cats['stage'] - 79.331 
date_stage = storm_stage_cats['date'] 
rainfall = storm_rain_cats['rainfall'] 
date_rainfall = storm_rain_cats['date'] 

#set locator and formatter 

hours = matplotlib.dates.HourLocator() # every year 
months = matplotlib.dates.MonthLocator() # every month 
hoursFmt = matplotlib.dates.DateFormatter('%H') 

#create plot 

fig=matplotlib.pyplot.figure() 
ax=fig.add_subplot(311) 
ax.bar(date_rainfall,rainfall,color='blue',label='Precipitation') 
ax.xaxis.set_major_locator(hours) 
ax.xaxis.set_major_formatter(hoursFmt) 
matplotlib.pyplot.ylabel('Precipitation[mm]') 
matplotlib.pyplot.grid(True) 
matplotlib.pyplot.legend() 

ax=fig.add_subplot(312) 
ax.plot(date,discharge,color='red',label='discharge') 
ax.xaxis.set_major_locator(hours) 
ax.xaxis.set_major_formatter(hoursFmt) 
matplotlib.pyplot.ylabel('discharge[m3/s]') 
matplotlib.pyplot.grid(True) 
matplotlib.pyplot.legend() 

ax=fig.add_subplot(313) 
ax.plot(date_stage,stage,color='green',label='stageheight') 
ax.xaxis.set_major_locator(hours) 
ax.xaxis.set_major_formatter(hoursFmt) 
matplotlib.pyplot.ylabel('stageheight[m]') 
matplotlib.pyplot.grid(True) 
matplotlib.pyplot.legend() 
matplotlib.pyplot.xlabel('Hours') 

fig=matplotlib.pyplot.figure(1) 
fig.autofmt_xdate() #rotates dates in xaxis 

回答