Tracé de graphique météo

Tracé de graphique météo

Tracé de graphique météo

Affichage dune courbe représentant la vitesse du vent pour une ville donnée.

Il faut

Un compte openweather (gratuit)

100% Complete

Objectifs

Nous allons voir comment installer la librairie graphique matplotlib de Python pour afficher une courbe montrant la vitesse du vent. La vitesse est relevée sur le site OpenWeather sur pour l'emplacement d'une ville 

Installation des librairies Python

Installation de la librairie :

sudo apt-get install python-matplotlib libatlas-base-dev

Le programme

forecast = session.get( "http://api.openweathermap.org/data/2.5/forecast?id=" + config.openWeatherCityName + "&units=metric&lang=fr&appid=" + config.openWeatherAPI)

weatherForcast = forecast.json()

weatherForcast = weatherForcast['list']

vitesseVent = []

labelle = []

# Keep only 9 first data

for forcast in weatherForcast[:9]:

    # extract the label

    letter = datetime.utcfromtimestamp(forcast['dt']).strftime('%a') # the day according to local abreviation

    letter = letter[:1].upper() + "." value = datetime.utcfromtimestamp(forcast['dt']).strftime('%Hh') labelle.append(letter + str(value))

    # extract the wind speed

    value = float(forcast['wind']['speed']) * 3.6

    vitesseVent.append(value)

# Create the graphic with wind speed ---------------------------------------------------------------

# figsize is in inch (depends of the dpi (72 by default))

fig = plt.figure(num=None, figsize=(7, 2), dpi=65, facecolor='w', edgecolor='k')

plt.plot( labelle, vitesseVent)

plt.title("Prévision vitesse vent (km/h) pour les prochaines 24h")

plt.ylabel('km/h')

plt.close()

fig.savefig(config.windSpeedPictureFile) # Save the graphique in this name's file

Copyright © 2015 Alex-design.fr All rights reserved.