我无法在从远程位置抓取并附加到列表中的坐标中绘制一条线。
以下是此文件的坐标列表:
[15.2,15.1,15.4,15.6,15.5,15.9,16.0,15.8,15.3,15.6,16.0,16.7,16.1,16.3,17.2,17.7,19.0,20.1,21.3,22.1,23.1,23.9,24.2, 24.2,25.2,26.1,26.4,27.1,27.5,28.1,28.7,29.0,29.2,29.6,30.0,30.3,30.9,31.7,32.7] [51.2,52.8,53.9,55.6,57.3,59.3,61.2,63.0,64.0 ,65.4,67.1,68.7,70.0,70.8,71.9,72.5,73.3,74.6,76.0,77.2,79.0,80.8,82.3,82.9,84.2,85.3,86.2,87.0,88.1,88.5,89.2,89.7,90.5,90.7 ,91.1,91.2,91.6,92.1,92.6]
以下是代码:
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as my_plot
from mpl_toolkits.basemap import Basemap
import urllib.request as url
def get_data(request_url):
req = url.urlopen(request_url)
lats = []
lons = []
for line in req:
clean_line = line.decode("utf-8")
space_split = clean_line.split()
if len(space_split) < 1:
continue
if space_split[0] == "INIT":
lats.append(float(space_split[2].replace("N", "")))
lons.append(float(space_split[3].replace("W", "")))
return lats,lons
lats, lons = get_data("http://vortex.plymouth.edu/hur_dir/2012/atl_09_isaac12_pos")
my_map = Basemap(llcrnrlon=-100.,llcrnrlat=0.,urcrnrlon=-20.,urcrnrlat=57.,
projection='lcc',lat_1=20.,lat_2=40.,lon_0=-60.,
resolution ='l',area_thresh=1000.)
fig = my_plot.figure()
my_map.drawcoastlines()
my_map.drawcountries()
my_map.drawstates()
my_map.drawmapboundary(fill_color='#6495ed')
my_map.fillcontinents(color = 'coral',lake_color='#6495ed')
x,y = my_map(lats,lons)
my_map.plot(x,y,linewidth=1.5,color='r')
my_plot.show()
关于为什么线不绘图的任何想法?
答案 0 :(得分:0)
绘制地图需要为负数的经度坐标,所以我添加了
lons = [x * -1 for x in lons]
之后,可以绘制数据。