使用python basemap绘制多个greatcircle图
解决此问题时遇到困难: 从阵列绘制多条大圆路径 错误消息: 回溯(最近一次调用last):文件“example.py”,第41行,在 eq_map.drawgreatcircle(y,x,y2,x2,线宽=6,color='b')文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site packages/mpl_工具包/basemap/init.py”, 第2893行,在drawgreatcircle中 npoints=int((dist+0.5*1000.*del_s)/(1000.*del_s))类型错误:只能将列表(而不是“float”)连接到列表使用python basemap绘制多个greatcircle图,python,matplotlib-basemap,great-circle,Python,Matplotlib Basemap,Great Circle,解决此问题时遇到困难: 从阵列绘制多条大圆路径 错误消息: 回溯(最近一次调用last):文件“example.py”,第41行,在 eq_map.drawgreatcircle(y,x,y2,x2,线宽=6,color='b')文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site packages/mpl_工具包/basemap/init.py”, 第2893行,在drawgreatcircle中 npo
Python代码:
import csv
# Open the data file.
filename = 'sample.csv'
# Create empty lists for the latitudes and longitudes.
lats, lons = [], []
lats2, lons2 = [], []
# Read through the entire file, skip the first line,
# and pull out just the lats and lons.
with open(filename) as f:
# Create a csv reader object.
reader = csv.reader(f)
# Ignore the header row.
next(reader)
# Store the latitudes and longitudes in the appropriate lists.
for row in reader:
lats.append(float(row[1]))
lons.append(float(row[2]))
lats2.append(float(row[4]))
lons2.append(float(row[5]))
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
eq_map = Basemap(projection='merc',llcrnrlat=-80,urcrnrlat=80,llcrnrlon=-180,urcrnrlon=180,lat_ts=20,resolution='c')
eq_map.drawcoastlines()
eq_map.drawcountries()
eq_map.fillcontinents(color = 'gray')
eq_map.drawmapboundary()
eq_map.drawmeridians(np.arange(0, 360, 30))
eq_map.drawparallels(np.arange(-90, 90, 30))
x,y = eq_map(lons, lats)
x2,y2 = eq_map(lons2,lats2)
eq_map.drawgreatcircle(y,x,y2,x2,linewidth=6,color='b')
plt.show()
Sample.csv
Origin,origLat,origLon,Dest,destLat,destLon
"jfk",40.641311,-73.778139,"lax",33.941589,-118.40853
"teb",40.849023,-74.062953,"mia",34.730283,136.508588
您的LON和LAT当前在列表中。您需要遍历以获得坐标
print(type(lons))
以下是我的想法:
for x, y, x2, y2 in zip(lats[0::1], lons[0::1], lats2[0::1], lons2[0::1]):
eq_map.drawgreatcircle(x, y, x2, y2, linewidth=2, color='b')
除非你也想要创建绘图,否则你不需要
x,y = eq_map(lons, lats)
x2,y2 = eq_map(lons2,lats2)
有情节
for lats, lons, lats2, lons2 in zip(lats[0::1], lons[0::1], lats2[0::1], lons2[0::1]):
x,y = eq_map(lons, lats)
x2,y2 = eq_map(lons2,lats2)
eq_map.plot(x, y, marker='.', color='r', markersize=10)
eq_map.plot(x2, y2, marker='.', color='r', markersize=10)
eq_map.drawgreatcircle(lons, lats, lons2, lats2, linewidth=2, color='b')
您的LON和LAT当前在列表中。您需要遍历以获得坐标
print(type(lons))
以下是我的想法:
for x, y, x2, y2 in zip(lats[0::1], lons[0::1], lats2[0::1], lons2[0::1]):
eq_map.drawgreatcircle(x, y, x2, y2, linewidth=2, color='b')
除非你也想要创建绘图,否则你不需要
x,y = eq_map(lons, lats)
x2,y2 = eq_map(lons2,lats2)
有情节
for lats, lons, lats2, lons2 in zip(lats[0::1], lons[0::1], lats2[0::1], lons2[0::1]):
x,y = eq_map(lons, lats)
x2,y2 = eq_map(lons2,lats2)
eq_map.plot(x, y, marker='.', color='r', markersize=10)
eq_map.plot(x2, y2, marker='.', color='r', markersize=10)
eq_map.drawgreatcircle(lons, lats, lons2, lats2, linewidth=2, color='b')