首页 > 代码库 > Data Visualizations 6

Data Visualizations 6

Visualize Geographic Data:

To deal with mutiple DataFrame

1. How to install a library into the Anaconda: In Jupyter Notebook, under tag Conda, we can install packages and save them into Anaconda > Lib > site-packages folder

2. Create a basemap instance with specific map projection about which part of map I wanna to include. Just like the figure in the plotting.

   m = Basemap (projection = "merc" , llcrnrlat = -80,urcrnrlat = 80, llcrnrlon = -180, urcrnrlon =180)

  • projection - the map projection.
  • llcrnrlat - latitude of lower left hand corner of the desired map domain (degrees).
  • urcrnrlat - latitude of upper right hand corner of the desired map domain (degrees).
  • llcrnrlon - longitude of lower left hand corner of the desired map domain (degrees).
  • urcrnrlon- longitude of upper right hand corner of the desired map domain (degrees)

3.  Convert spherical coordinates to cartesian coordinates using the Basemap instance.

   Convert Spherical coordinates : [145.39188100000001, 145.78870000000001, 144.295861, 146.72624199999998, 147.22004999999999]

   Basemap instance: [36181909.301050939, 36226033.539869711, 36060037.494937442, 36330283.404696316, 36385192.323177092]

   By using basemap instance:

    longitudes = airports["longitude"].tolist()
    latitudes = airports["latitude"].tolist()

    x, y = m(longitudes, latitudes) # The argument of basecamp m only accept list. So we have to convert the Dataframe column to list first by using .tolist().

4.  m.scatter(x,y) #present the location point in the map. x and y are cardisian coordinates which is converted from the DataFrame and stored as a list.

5.  Once you create a figure. Every graphic you create under the figure is in the figure.

6.  The first way to combine two Dataframe together is to create a new DataFrame which only contains necessary datas and put it into one csv file.

7.  To draw lines for each circle by using drawgreatcircle method:

  fig = plt.figure(figsize=(15,20))
  m = Basemap(projection=‘merc‘, llcrnrlat=-80, urcrnrlat=80, llcrnrlon=-180, urcrnrlon=180)
  m.drawcoastlines()

  def create_great_circles(df):
  for index, row in df.iterrows():
  start_lon = row[‘start_lon‘]
  start_lat = row[‘start_lat‘]
  end_lon = row[‘end_lon‘]
  end_lat = row[‘end_lat‘]

  if abs(end_lat - start_lat) < 180 and abs(end_lon - start_lon) < 180:
  m.drawgreatcircle(start_lon, start_lat, end_lon, end_lat, linewidth=1)

  dfw = geo_routes[geo_routes["source"] == "DFW"]

  create_great_circles(dfw)

Data Visualizations 6