我有一个数据集,我想在网格框中绘制数据。对我来说最好的方式似乎是for循环,但我无法让它工作。我对代码应该是什么的假设是:
for lat in range(53.22010374071,53.46673202514641) & lon in range(1.22201037407, 1.33312034607):
它出现了错误:
TypeError: range() integer end argument expected, got float.
答案 0 :(得分:1)
build in range()仅适用于整数循环。尝试使用例如numpy linspace : import numpy
lat_start = 53.22010374071
lat_stop = 53.46673202514641
lon_start = 1.22201037407
lon_stop = 1.33312034607
for lat in numpy.linspace( lat_start, lat_stop, 100 ):
for lon in numpy.linspace( lon_start, lon_stop, 100 ):
print "Doing grid at %f %f " % (lat,lon)
给我的输出如下:
Doing grid at 53.441820 1.283738
Doing grid at 53.441820 1.284860
Doing grid at 53.441820 1.285983
Doing grid at 53.441820 1.287105