Here is my question.
Now, I can plot the terrain as background using contourf in matplotlib.
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
As the background, it may affect the overlay plot(different color mingle together).
The figure I found on a book which I upload below is a good visualization art.
http://i11.tietuku.com/4d4178c16eb7aaf6.png
The terrain as the background doesn't bother the overlayed drainage basin(green) at all.
So, how to plot this similar-kind of shady terrain using matplotlib, I tried some colormap, but I can't get an alike plotting.
I have already tried the alpha setting with code below:
# 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)
The figure shows like this:
http://i11.tietuku.com/5bb0b4cb0102ec32.png
Regardless of the data I was using is different from the watershed area. What I'm committed to is to depict the topographic relief more realistic like fig.2 which I post here.
You just needed to a) align both plots b) add the alpha
keyword for plots:
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With