Basemap
今天學(xué)習(xí)了使用Basemap進(jìn)行數(shù)據(jù)可視化衡载,主要參考Kaggle上的這個Kernel:Geolocation visualisations篓吁。
輸出效果如下:
圖片.png
讀入數(shù)據(jù)后的結(jié)果:
圖片.png
核心代碼如下:
# Sample it down to only the China region
# 設(shè)置中國的經(jīng)緯度范圍
lon_min, lon_max = 75, 135
lat_min, lat_max = 15, 55
# 取出數(shù)據(jù)中屬于中國的數(shù)據(jù)
idx_china = (df_events["longitude"]>lon_min) & (df_events["longitude"]<lon_max) & (df_events["latitude"]>lat_min) & (df_events["latitude"]<lat_max)
df_events_china = df_events[idx_china].sample(n=100000)
# 數(shù)據(jù)可視化
plt.figure(2, figsize=(12,6))
m2 = Basemap(projection='merc', #投影方式
llcrnrlat=lat_min,
urcrnrlat=lat_max,
llcrnrlon=lon_min,
urcrnrlon=lon_max,
lat_ts=35,
resolution='c') #分辨率
m2.fillcontinents(color='#191919',lake_color='#000000') # dark grey land, black lakes
m2.drawmapboundary(fill_color='#000000') # black background
m2.drawcountries(linewidth=0.1, color="w") # thin white line for country borders
# Plot the data
mxy = m2(df_events_china["longitude"].tolist(), df_events_china["latitude"].tolist())
m2.scatter(mxy[0], mxy[1], s=5, c="#1292db", lw=0, alpha=0.05, zorder=5)
plt.title("China view of events")
plt.show()