Python Keyerror:创建绘图时为1
我正在绘制飞行路线图 有两个数据帧:航班2021和新冠肺炎之前的航班。我想在同一张地图上添加新冠病毒之前的航班 协调21:covid期间的直飞目的地 坐标_pre_covid:在covid之前航班可用,而在covid期间航班不可用的直接航班目的地Python Keyerror:创建绘图时为1,python,matplotlib,cartopy,Python,Matplotlib,Cartopy,我正在绘制飞行路线图 有两个数据帧:航班2021和新冠肺炎之前的航班。我想在同一张地图上添加新冠病毒之前的航班 协调21:covid期间的直飞目的地 坐标_pre_covid:在covid之前航班可用,而在covid期间航班不可用的直接航班目的地 tll = coordinates21.loc[coordinates21['IATA'] == 'TLL'] # Create plot for every airport in coordinates21 for row in range(coo
tll = coordinates21.loc[coordinates21['IATA'] == 'TLL']
# Create plot for every airport in coordinates21
for row in range(coordinates21.shape[0]):
# make curve lines that connect TLL to the destination
plt.plot([tll['Longitude'].values[0], coordinates21['Longitude'].at[row]], [tll['Latitude'].values[0], coordinates21['Latitude'].at[row]], color='blue',linewidth=2,marker='o',transform=ccrs.Geodetic())
# write airports' IATA codes according to given coordinates (lon&lan)
plt.text(coordinates21['Longitude'].at[row], coordinates21['Latitude'].at[row], coordinates21['IATA'].at[row], fontsize='16', transform=ccrs.Geodetic(),)
# Create plot for every airport in coordinates_pre_covid
for row in range(coordinates_pre_covid.shape[0]):
# make curve lines from TLL to direct destinations
plt.plot([tll['Longitude'].values[0], coordinates_pre_covid['Longitude'].at[row]], [tll['Latitude'].values[0], coordinates_pre_covid['Latitude'].at[row]], color='blue',linewidth=2,marker='o',transform=ccrs.Geodetic())
# write airports' IATA codes according to given coordinates (lon&lan)
plt.text(coordinates_pre_covid['Longitude'].at[row], coordinates_pre_covid['Latitude'].at[row], coordinates_pre_covid['IATA'].at[row], fontsize='16', transform=ccrs.Geodetic(),)
该图仅适用于新冠病毒飞行期间的飞行,而不适用于新冠病毒飞行前的飞行。我不断得到错误Keyerror:1,似乎问题发生在这一行:
plt.plot([tll['Longitude'].values[0], coordinates_pre_covid['Longitude'].at[row]], [tll['Latitude'].values[0], coordinates_pre_covid['Latitude'].at[row]], color='blue',linewidth=2,marker='o',transform=ccrs.Geodetic())
Keyerror:1在这里表示什么
谢谢要在同一地图上绘制多个数据层(或
轴
),必须先创建轴,即ax1=plt.axes(…)
。然后,在每个plot语句中,使用ax1.plot(…)
在同一地图上创建图形。