Ich habe eine CSV-Datei mit Daten von 6 Jahren (Datum, Länge, Breite, Wert) Ich habe die Dichte Karte mit Histogramm2d und Konturf pro km, ich habe eine schöne Karte, aber ich glaube dass ich die dichte pro km pro 6 jahre aufgetragen habe, so muss ich die berücksichtigungskriterien berücksichtigen, wie viele jahre ich in der datei habe und die dichte pro km pro jahr und nicht pro 6 jahre aufzeige. so hier ist der Code, den ich dies zu erreichen bin mit:Plotten Dichtekarte pro km2 pr Jahr
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()
Irgendwelche Ideen ??
sollten Sie detaillierter angeben, wie Ihre Daten aussehen, z. wie die "Zeit" bezeichnet wird. Außerdem scheint Ihre Herangehensweise etwas verworren: Haben Sie überlegt, Pandas zum Einlesen Ihrer Daten zu verwenden? – Daan
Zeitstempel, heure, lat, lon, Impact, Typ 2007-01-01 00: 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: 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 –