有效数据外含有额外数据_basemap之地图上画额外数据
生活随笔
收集整理的這篇文章主要介紹了
有效数据外含有额外数据_basemap之地图上画额外数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
有時候我們想將自己的數據畫在地圖上,比如點,線,熱體圖等。我們先畫地圖地形底圖,然后將數據點畫在地圖之上。
1. 散點 Basemap.scatter()
比如我們經常會將站點畫在地圖上,如地震臺站,下圖中的藍色倒三角,以及震中(紅色五角星)。
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemapn = 51 x = np.random.randn(n) * 180 y = np.random.randn(n) * 90map = Basemap() map.shadedrelief(scale=0.1) map.drawparallels(circles=np.linspace(-90, 90, 7),labels=[1, 0, 0, 0], color='gray') map.drawmeridians(meridians=np.linspace(-180, 180, 13),labels=[0, 0, 0, 1], color='gray') map.scatter(x, y, marker='v', s=100, facecolor='#00BFFF',edgecolor='k', linewidth=1) map.scatter(0, 0, marker='*', s=450, facecolor='r',edgecolor='k', linewidth=1) plt.show()2. 畫大圓弧 Basemap.drawgreatcircle()
我們將地震震中和地震臺站連起來,由于地圖投影方式不同,畫出來的曲線形態存在差異,一般大圓弧都是彎曲的。
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemapn = 21 x = np.random.randn(n) * 30 y = np.random.randn(n) * 15 x0 = -100; y0 = 30 map = Basemap() map.shadedrelief(scale=0.1) map.drawparallels(circles=np.linspace(-90, 90, 7),labels=[1, 0, 0, 0], color='gray') map.drawmeridians(meridians=np.linspace(-180, 180, 13),labels=[0, 0, 0, 1], color='gray') order = 0 for (xx, yy) in zip(x, y):map.drawgreatcircle(x0, y0, xx, yy, zorder=order)order += 1 map.scatter(x, y, marker='v', s=100, facecolor='#00BFFF',edgecolor='k', linewidth=1, zorder=order+1) map.scatter(x0, y0, marker='*', s=450, facecolor='r',edgecolor='k', linewidth=1, zorder=order+1) plt.show()3. 畫熱力圖 Basemap.pcolormesh()
有時候我們需要將二維的熱力圖畫在地圖之上,比如大地震發生后產生海嘯,波在海面表現出的波浪形態?,F生成二維數據,再將之畫在地圖之上。
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemapx = np.linspace(-180, 180, 121) y = np.linspace(-90, 90, 121) X, Y = np.meshgrid(x, y) Z = np.exp(-(X**2+Y**2)/3000) * np.sin((X**2+Y**2)/2000) - 0.15map = Basemap() map.pcolormesh(x, y, Z, cmap='CMRmap', zorder=0) map.colorbar(shrink=0.5) map.fillcontinents(color='gray', zorder=1) map.drawparallels(circles=np.linspace(-90, 90, 7),labels=[1, 0, 0, 0], color='gray') map.drawmeridians(meridians=np.linspace(-180, 180, 13),labels=[0, 0, 0, 1], color='gray') map.drawcoastlines(color='w', linewidth=0.5) map.scatter(0, 0, marker='*', s=450, facecolor='r',edgecolor='k', linewidth=1, zorder=2) plt.show()4. 等值線圖 Basemap.contourf()和Basemap.contour()
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemapx = np.linspace(-180, 180, 121) y = np.linspace(-90, 90, 121) X, Y = np.meshgrid(x, y) Z = np.exp(-(X**2+Y**2)/3000) * np.sin((X**2+Y**2)/2000) - 0.15map = Basemap() map.contourf(X, Y, Z, cmap='CMRmap', zorder=0) map.colorbar(shrink=0.5) CS = map.contour(X, Y, Z, cmap='CMRmap', zorder=0.1) ax = plt.gca() ax.clabel(CS, inline=True, fmt='%1.1f', fontsize=14) map.fillcontinents(color='gray', zorder=1) map.drawparallels(circles=np.linspace(-90, 90, 7),labels=[1, 0, 0, 0], color='gray') map.drawmeridians(meridians=np.linspace(-180, 180, 13),labels=[0, 0, 0, 1], color='gray') map.drawcoastlines(color='w', linewidth=0.5) map.scatter(0, 0, marker='*', s=450, facecolor='r',edgecolor='k', linewidth=1, zorder=2) plt.show()5. 矢量場 Basemap.quiver()
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemapx = np.linspace(-180, 180, 31) y = np.linspace(-90, 90, 31) X, Y = np.meshgrid(x, y) U = np.sin(X+Y) V = np.cos(X+Y)map = Basemap() map.shadedrelief(scale=0.1) map.quiver(X, Y, U*250, V*0.1, abs(U+V), cmap='gnuplot') plt.colorbar(shrink=0.75) map.drawparallels(circles=np.linspace(-90, 90, 7),labels=[1, 0, 0, 0], color='gray') map.drawmeridians(meridians=np.linspace(-180, 180, 13),labels=[0, 0, 0, 1], color='gray') plt.show()總結
以上是生活随笔為你收集整理的有效数据外含有额外数据_basemap之地图上画额外数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shiro将session认证改成tok
- 下一篇: zabbix历史数据mysql_处理Za