Building terrain as background using matplotlib

Here is my question.

  • the landscape represented height in this area. I downloaded here

Now I can build the landscape as a background using the outline 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 a background, this can affect the blending schedule (mixed color).

The drawing I found in the book that I download below is a good art of visualization.

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

The landscape as a background does not bother the overlay drainage pool (green) at all.

So, how to build a similar kind of shady area using matplotlib, I tried some color grading, but I can’t get a similar plot.

Update

I already tried setting alpha with the 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 the following:

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

Regardless of the data I used, it is different from the watershed area. What I intend to do is portray the topographic terrain more realistic , as shown in Figure 2, which I post here.

+5
source share
1 answer

You just need to: a) align both graphs; b) add the alpha keyword for graphs:

 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() 
+1
source

Source: https://habr.com/ru/post/1244114/


All Articles