Jul-31-2019, 05:24 PM
i trying to build a a graph from an api of weather website. i want the user will input 3 cities that i would like to know and then make a dictionry from the api {name of the city: the currently temp from the api} and then make the dictionry to a graph :
(x: name of the city , y: current temperature from the api)
(x: name of the city , y: current temperature from the api)
def read_key_from_file(): hFile = open(file_name,'r') for line in hFile: Mykey = line hFile.close() Mykey = line return Mykey def get_geo_location(location): location = Nominatim().geocode(location) lat = location.latitude lon = location.longitude return location, lat, lon def comperison_graph(Mykey): if daily_temp_dict == {}: a = input("Enter first city name in lower case letter: ") daily_temp_dict[a] = "" b = input("Enter second city name in lower case letter: ") daily_temp_dict[b] = "" c = input("Enter third city name in lower case letter: ") daily_temp_dict[c] = "" for city in daily_temp_dict.keys(): location, lat, lon = get_geo_location(city) forecast = forecastio.load_forecast(Mykey, lat, lon) daily_temp_dict[city] = forecast.currently().temperature data = daily_temp_dict names = list(data.keys()) print(names) values = list(data.values()) print(values) plt.bar(0,values[0],tick_label=names[0]) plt.bar(1,values[1],tick_label=names[1]) plt.bar(2,values[2],tick_label=names[2]) plt.xticks(range(0,3),names) plt.savefig('fruit.png') plt.show()the problem is that im getting in a result a graph like this :
https://imgur.com/raVSVxH
and i need only the last one