You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 3
Next »
import requests
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime
url = 'http://localhost:8080/FewsWebServices/rest/fewspiservice/v1/timeseries'
params = dict(
documentVersion='1.23',
documentFormat='PI_JSON',
locationIds=['acnj'],
parameterIds=['H.observed'],
startTime='2017-06-20T00:00:00Z',
endTime ='2017-06-22T00:00:15Z',
)
response = requests.get(url=url, params=params)
data = response.json()
timeSeries = data['timeSeries']
timeZoneValue = float(data['timeZone'])
timeZone = f"{timeZoneValue:05.2f}"
timeZone = timeZone.replace(".", "")
if timeZoneValue >= 0:
timeZone = "+" + timeZone
else:
timeZone = "-" + timeZone
x = []
y = []
for timeSerie in timeSeries:
if 'events' in timeSerie:
header = timeSerie['header']
for event in timeSerie['events']:
x.append(datetime.datetime.strptime(event['date'] + ' ' + event['time'] + ' ' + timeZone, '%Y-%m-%d %H:%M:%S %z'))
y.append(event['value'])
dateFormatter = mdates.DateFormatter('%B %d %H:%M')
fig, ax = plt.subplots()
ax.plot(x, y, label='H.obs')
ax.xaxis.set_major_formatter(dateFormatter)
ax.xaxis.set_major_locator(plt.MaxNLocator(5))
ax.yaxis.set_major_locator(plt.MaxNLocator(10))
ax.grid(True)
plt.show()