美文网首页
使用Basemap做数据可视化

使用Basemap做数据可视化

作者: 易思涵 | 来源:发表于2017-12-15 20:35 被阅读0次

Basemap

今天学习了使用Basemap进行数据可视化,主要参考Kaggle上的这个Kernel:Geolocation visualisations
输出效果如下:

图片.png

读入数据后的结果:

图片.png

核心代码如下:

# Sample it down to only the China region
# 设置中国的经纬度范围
lon_min, lon_max = 75, 135
lat_min, lat_max = 15, 55

# 取出数据中属于中国的数据
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)

# 数据可视化
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()

相关文章

网友评论

      本文标题:使用Basemap做数据可视化

      本文链接:https://www.haomeiwen.com/subject/wazdwxtx.html