thorpedosg

hVHZy90J

Aug 6th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. AttributeError: 'NoneType' object has no attribute 'longitude'
  2.  
  3. import matplotlib.pyplot as plt
  4. from mpl_toolkits.basemap import Basemap
  5. from geopy.geocoders import Nominatim
  6. import math
  7.  
  8. city_list = list(flight_data["OriginCityName"].unique())
  9. cities = city_list
  10. scale = 1
  11.  
  12. map = Basemap(width=10000000,height=6000000,projection='lcc',
  13. resolution=None,lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
  14. plt.figure(figsize=(19,20))
  15. map.bluemarble()
  16.  
  17.  
  18. # Get the location of each city and plot it
  19. geolocator = Nominatim()
  20. for city in cities:
  21. loc = geolocator.geocode(city)
  22. if not loc:
  23. print("Could not locate {}".format(city))
  24. continue
  25. x, y = map(loc.longitude, loc.latitude)
  26. map.plot(x,y,marker='o',color='Red',markersize=5)
  27. plt.annotate(city, xy = (x,y), xytext=(-20,20))
  28. plt.show()
  29.  
  30. for city in cities:
  31. loc = geolocator.geocode(city)
  32. if not loc:
  33. print("Could not locate {}".format(city))
  34. continue
  35. x, y = map(loc.longitude, loc.latitude)
  36. map.plot(x,y,marker='o',color='Red',markersize=int(math.sqrt(count))*scale)
  37. plt.annotate(city, xy = (x,y), xytext=(-20,20))
Add Comment
Please, Sign In to add comment