使用matplotlib绘制地形作为背景

2024-09-21 03:21:18 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的问题。在

  • 地形是由这些地区的海拔高度来表示的。我上传了here

现在可以用轮廓图库绘制地形图了。在

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)

http://i13.tietuku.com/1d32bfe631e20eee.png

作为背景,可能会影响叠加图(不同颜色混合在一起)。在

我在下面上传的一本书上发现的这个图形是一种很好的视觉艺术。在

http://i11.tietuku.com/4d4178c16eb7aaf6.png

作为背景的地形根本不会影响叠加的流域(绿色)。在

所以,如何用matplotlib绘制这种类似的阴影地形,我尝试了一些彩色地图,但我不能得到一个相同的绘图。在

更新

我已经用下面的代码尝试过alpha设置:

^{pr2}$

如图所示:

http://i11.tietuku.com/5bb0b4cb0102ec32.png

不管我使用的数据是不同于流域的。我致力于描绘更真实的地形起伏,如我在这里发布的图2所示。在


Tags: csvalphacomhttppngnp绘制plt
1条回答
网友
1楼 · 发布于 2024-09-21 03:21:18

您只需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()

相关问题 更多 >

    热门问题