未在底图上绘制线 Python
Line Not Plotting on Basemap Python
我无法根据从远程位置抓取并附加到列表中的坐标绘制直线。
这是来自这个文件的坐标列表:
[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()
关于为什么这条线没有绘制的任何想法?
绘制地图的经度坐标需要为负数,所以我添加了
lons = [x * -1 for x in lons]
之后,就可以绘制数据了。
我无法根据从远程位置抓取并附加到列表中的坐标绘制直线。
这是来自这个文件的坐标列表:
[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()
关于为什么这条线没有绘制的任何想法?
绘制地图的经度坐标需要为负数,所以我添加了
lons = [x * -1 for x in lons]
之后,就可以绘制数据了。