Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 绘制每年每平方公里的密度图_Python 2.7_Contourf_Histogram2d - Fatal编程技术网

Python 2.7 绘制每年每平方公里的密度图

Python 2.7 绘制每年每平方公里的密度图,python-2.7,contourf,histogram2d,Python 2.7,Contourf,Histogram2d,我有一个csv文件,包含6年的数据(日期、经度、纬度、值)我用Historogram2D和contourf per km绘制了密度图,我得到了一张漂亮的地图,但我相信我绘制了每6年每km的密度,因此,我需要考虑知道文件中有多少年的标准,并绘制每年每公里的密度,而不是每6年的密度。 下面是我用来实现这一目标的代码: with open('flash.csv') as f: reader = csv.reader(f) next(reader) # Ignore the header row. lo

我有一个csv文件,包含6年的数据(日期、经度、纬度、值)我用Historogram2D和contourf per km绘制了密度图,我得到了一张漂亮的地图,但我相信我绘制了每6年每km的密度,因此,我需要考虑知道文件中有多少年的标准,并绘制每年每公里的密度,而不是每6年的密度。 下面是我用来实现这一目标的代码:

with open('flash.csv') as f:
reader = csv.reader(f)
next(reader) # Ignore the header row.
lonMin, lonMax, dLon = -20.0, 5.0, 5
latMin, latMax, dLat = 18.0, 40.0, 5
for row in reader:
    lat = float(row[2])
    lon = float(row[3])
    # filter lat,lons to (approximate) map view:
    if lonMin <= lon <= lonMax and latMin <= lat <= latMax:
        lats.append( lat )
        lons.append( lon )

m = Basemap(llcrnrlon=min(lons), llcrnrlat=min(lats), urcrnrlon=max(lons), urcrnrlat=max(lats), projection='merc', resolution='f')

numcols = (max(lons)-min(lons)) * 100
numrows = (max(lats)-min(lats)) * 100

db = 1
lon_bins = np.linspace(min(lons)-db, max(lons)+db, numcols)
lat_bins = np.linspace(min(lats)-db, max(lats)+db, numrows) 
h, xedges, yedges = (np.histogram2d(lats, lons,[lat_bins, lon_bins]))
xi, yi= m(*np.meshgrid(lon_bins, lat_bins))

#shape into continuous matrice
g = np.zeros(xi.shape)
g[:-1,:-1] = h
g[-1] = g[0]      # copy the top row to the bottom
g[:,-1] = g[:,0]  # copy the left column to the right
print g.shape,yi.shape,xi.shape

m.drawcoastlines()
m.drawstates()

g[g==0.0] = np.nan
cs = m.contourf(xi, yi, g)
cbar = plt.colorbar(cs, orientation='horizontal')
cbar.set_label('la densite des impacts foudre',size=18)

plt.gcf().set_size_inches(15,15)
plt.show()
打开('flash.csv')作为f的
:
读卡器=csv。读卡器(f)
下一步(读卡器)#忽略标题行。
lonMin,lonMax,dLon=-20.0,5.0,5
latMin,latMax,dLat=18.0,40.0,5
对于读取器中的行:
lat=浮动(第[2]行)
lon=浮动(第[3]行)
#过滤lat、lons至(近似)地图视图:

如果lonMin我刚刚找到了我问题的解决方案,我这样做是为了获得我在csv文件中的年数,我将计算出的密度划分为NB年,它工作得很好

DateMax = data.index.year.max()
DateMin = data.index.year.min()
NByears = (DateMax - DateMin)

您应该提供有关数据外观的更多详细信息,例如“时间”是如何表示的。此外,你的方法似乎有点复杂:你考虑过使用熊猫来读取数据吗?时间戳,heure,lat,lon,impact,键入2007-01-01 00:00,13:58:43,33.837,-9.205,10.3,1 2007-01-02 00:00:00,00:07:28,34.5293,-10.2384,17.7,1 2007-01-02 00:00,23:01:03,35.0617,-1.435,-17.1,2 2007-01-03 00:00:00,01:14:29,36.5685,0.9043,36.8,1 2007-01-03 00:00:00,05:03:51,34.1919,-12.5061,-48.9,1