Han*_*gzu 5 python gis visualization matplotlib matplotlib-basemap
这是我的问题.
现在,我可以使用matplotlib中的contourf将地形绘制为背景.
fig =plt.figure(figsize=(10,8))
ax = plt.subplot()
xi,yi = np.linspace(195.2260,391.2260,50), np.linspace(4108.9341,4304.9341,50)
height = np.array(list(csv.reader(open("terr_grd.csv","rb"),delimiter=','))).astype('float')
terrf = plt.contourf(xi, yi, height,15, cmap=plt.cm.Blues)
terr = plt.contour(xi, yi, height, 15,
colors='k',alpha=0.5)
plt.clabel(terr, fontsize=9, inline=1)
Run Code Online (Sandbox Code Playgroud)
http://i13.tietuku.com/1d32bfe631e20eee.png
作为背景,它可能会影响叠加图(不同颜色混合在一起).
我在上面上传的书中找到的图是一个很好的可视化艺术.
http://i11.tietuku.com/4d4178c16eb7aaf6.png
作为背景的地形根本不会打扰覆盖的排水盆(绿色).
所以,如何使用matplotlib绘制这种类似的阴影地形,我尝试了一些色彩图,但我无法得到相似的绘图.
我已经使用以下代码尝试了alpha设置:
# Z is 2-d array represent the value of each grid
CS = plt.contourf(xi,yi, Z,2, cmap=plt.cm.Greens,
vmax=abs(Z).max(), vmin=abs(Z).min(),alpha=0.8,zorder = 3)
Run Code Online (Sandbox Code Playgroud)
该图显示如下:
http://i11.tietuku.com/5bb0b4cb0102ec32.png
无论我使用的数据与流域区域有什么不同.我所承诺的是将地形浮雕描绘得更加逼真,如图2所示.
您只需要 a) 对齐两个图 b) 添加alpha
图的关键字:
fig =plt.figure(figsize=(10,8))
ax = plt.subplot()
xi,yi = np.linspace(195.2260,391.2260,50), np.linspace(4108.9341,4304.9341,50)
## the image
img=mpimg.imread('4d4178c16eb7aaf6.png')
ax.imshow(img,
extent=[min(xi), max(xi), min(yi), max(yi)])
## the rest
height = np.array(list(csv.reader(open("terr_grd.csv","tr"),delimiter=','))).astype('float')
terrf = ax.contourf(xi, yi, height,15, cmap=plt.cm.Blues,alpha=0.5)
terr = ax.contour(xi, yi, height, 15,
colors='k',alpha=0.5)
ax.clabel(terr, fontsize=9, inline=1)
fig.savefig("theplot.png")
plt.show()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
651 次 |
最近记录: |