无法在 matplotlib 中以度数绘制坐标

Trouble plotting coordinates in degrees in matplotlib

因此,我目前正在处理导入到 python 中的 GTFS 数据。我有这个 table bronx_frequencyTable,其中包含 shape_pt_lonshape_pt_lat 中的纵向坐标。但是,当我 运行 以下代码时:

for index, row in bronx_frequencyTable.iterrows():
    map.plot(row['shape_pt_lon'], row['shape_pt_lat'], latlon=True, linestyle='solid')

plt.show()

除了我已经绘制的海岸线之外,实际上什么也没有出现。有人知道我如何根据我的数据绘制线条吗?

数据:

        shape_id  shape_pt_lat  shape_pt_lon  shape_pt_sequence  num_trips
0       BX010026     40.809663    -73.928240              10001        143
1       BX010026     40.809620    -73.928135              10002        143
2       BX010026     40.810075    -73.927781              10003        143
3       BX010026     40.810130    -73.927698              10004        143
4       BX010026     40.810860    -73.927191              10005        143
5       BX010026     40.810970    -73.927140              10006        143
6       BX010026     40.811036    -73.927223              10007        143
7       BX010026     40.811104    -73.927310              10008        143
8       BX010026     40.811725    -73.928126              10009        143
9       BX010026     40.812036    -73.928541              10010        143
10      BX010026     40.812338    -73.928949              10011        143
11      BX010026     40.812621    -73.929328              10012        143
12      BX010026     40.812722    -73.929458              10013        143
13      BX010026     40.812733    -73.929476              10014        143
14      BX010026     40.812816    -73.929515              10015        143
15      BX010026     40.812840    -73.929544              10016        143
16      BX010026     40.812912    -73.929631              10017        143
17      BX010026     40.813090    -73.929844              10018        143
18      BX010026     40.813521    -73.929548              10019        143
19      BX010026     40.813521    -73.929548              20001        143
20      BX010026     40.814235    -73.929059              20002        143
21      BX010026     40.814418    -73.928990              20003        143
22      BX010026     40.814863    -73.928787              20004        143
23      BX010026     40.816515    -73.928149              20005        143
24      BX010026     40.816820    -73.928027              20006        143
25      BX010026     40.816820    -73.928027              30001        143
26      BX010026     40.817198    -73.927874              30002        143
27      BX010026     40.817568    -73.927700              30003        143
28      BX010026     40.817632    -73.927668              30004        143
29      BX010026     40.818540    -73.927240              30005        143
...          ...           ...           ...                ...        ...
41788  SBS410037     40.870280    -73.878387              90011        365
41789  SBS410037     40.870338    -73.878271              90012        365
41790  SBS410037     40.870680    -73.877612              90013        365
41791  SBS410037     40.871047    -73.876928              90014        365
41792  SBS410037     40.871118    -73.876827              90015        365
41793  SBS410037     40.871217    -73.876700              90016        365
41794  SBS410037     40.871402    -73.876513              90017        365
41795  SBS410037     40.871402    -73.876513             100001        365
41796  SBS410037     40.872958    -73.874939             100002        365
41797  SBS410037     40.873167    -73.874765             100003        365
41798  SBS410037     40.873383    -73.874570             100004        365
41799  SBS410037     40.875086    -73.873225             100005        365
41800  SBS410037     40.876954    -73.871996             100006        365
41801  SBS410037     40.877075    -73.871938             100007        365
41802  SBS410037     40.878013    -73.871755             100008        365
41803  SBS410037     40.878392    -73.871661             100009        365
41804  SBS410037     40.878392    -73.871661             110001        365
41805  SBS410037     40.878644    -73.871598             110002        365
41806  SBS410037     40.878616    -73.871378             110003        365
41807  SBS410037     40.878396    -73.870496             110004        365
41808  SBS410037     40.878352    -73.870330             110005        365
41809  SBS410037     40.878228    -73.869842             110006        365
41810  SBS410037     40.878206    -73.869762             110007        365
41811  SBS410037     40.877798    -73.868049             110008        365
41812  SBS410037     40.877632    -73.867377             110009        365
41813  SBS410037     40.877505    -73.866849             110010        365
41814  SBS410037     40.877445    -73.866643             110011        365
41815  SBS410037     40.877373    -73.866415             110012        365
41816  SBS410037     40.877326    -73.866271             110013        365
41817  SBS410037     40.877769    -73.866017             110014        365

完整代码:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
import pandas as pd

#Calculate base frequency.
base_max_routes = 4
base_directions = 2
base_minhour = 7
base_maxhour = 19
base_bph = 6
base_frequency = base_max_routes * base_directions * (base_maxhour - base_minhour) * base_bph

# Read the shape files from the bus data.
bronx_shapes = pd.read_csv('../Bronx Data/shapes.txt')
bronx_trips = pd.read_csv('../Bronx Data/trips.txt')
bronx_numTrips = bronx_trips.groupby('shape_id').size()
bronx_numTrips.name = 'num_trips'

bronx_frequencyTable = bronx_shapes.join(bronx_numTrips, on=['shape_id'], how='inner')
print(bronx_frequencyTable)

# Create a map of New York City centered on Manhattan.
map = Basemap(resolution="h", projection="stere", width=50000, height=50000, lon_0=-73.935242, lat_0=40.730610)
map.drawcoastlines()

# Map the bus routes.
for index, row in bronx_frequencyTable.iterrows():
     map.plot(row['shape_pt_lon'], row['shape_pt_lat'], latlon=True, linestyle='solid')

plt.show()

您正在逐点绘制。相反,您应该直接绘制列:

map.plot(bronx_frequencyTable['shape_pt_lon'], bronx_frequencyTable['shape_pt_lat'], latlon=True, linestyle='solid')