I was trying to plot the data from a csv file which contains the date and some wind speed. Here is the final plot:
My problem is how to make the boundary same as the input data, which starts at 01/06/2017 13:00 and ends at 01/06/2017 22:00
My data:
time unnamed: 1 Unnamed: 2
22 01/06/2017 13:00 22.48
23 01/06/2017 16:00 24.96
24 01/06/2017 19:00 23.18
25 01/06/2017 22:00 19.86
..
41 10
47 5
53 8
60 6
My code:
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
a = pd.read_csv('J:/internship/forecast/6.1/forecast_report_Bahrain.csv')
m10wind = a['Unnamed: 2'][22:26]
slp = a['Unnamed: 11'][22:26]
temperature = a['Unnamed: 7'][22:26]
winddirection=a['Unnamed: 1'][22:26]
time= pd.to_datetime(a['Title: Forecast for Xiaoshen-Bahrain'][22:26])
#=============observations============
wind=a['Unnamed: 16'][41:60:6]
hour_3=mdates.HourLocator(interval=3)
fig, ax = plt.subplots()
fig.autofmt_xdate()
fig,ax.set_xlabel("Time(+3UTC)")
fig,ax.set_ylabel("10m wind speed (knots)")
ax.xaxis.set_major_locator(hour_3)
fig,ax.set_title("Forecast Wind Spped and Observations on June 1st 2017")
xfmt = mdates.DateFormatter('%d-%m-%y %H:%M')
ax.xaxis.set_major_formatter(xfmt)
ax.plot_date(time, m10wind, color='b',marker='s',label='GFS Forecast')
ax.plot_date(time, wind, color='r',marker='o', label='Wind Finder Observation')
leg = ax.legend(loc=2, bbox_to_anchor=(1.05, 1.0))
plt.savefig('1st June wind of Bahrain.png', bbox_inches='tight')
plt.show()