In python, overlay 4 types of diagrams: background diagram, contour diagram, vector diagram, and color plot diagram. The background diagram uses shp files, contour diagrams, vector diagrams, and color plot diagrams all use 2D grid data.
You can easily load and draw the background map with geopandas. In addition, when installing geopandas with pip, it did not work unless GDAL and Fiona were installed first.
import geopandas as gpd
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
#--1.Background drawing-------------------
shapefile='line.shp'
data = gpd.read_file(shapefile)
ax.set_xlim([-100000,0])
ax.set_ylim([-120000,-60000])
data.plot(ax=ax, color='black')
#-------------------------------
plt.show()
Read the mesh data and draw the color contour with pcolor mesh. Overlay the above background diagram from the top of the color contour.
import geopandas as gpd
import matplotlib.pyplot as plt
from matplotlib.colors import Normalize
import numpy as np
from matplotlib.cm import ScalarMappable
#
# (Data reading ⇒ X,Y,Z):abridgement
fig, ax = plt.subplots()
#--2.Color mesh drawing-------------------------------
fig, ax = plt.subplots()
norm = Normalize(vmin=-500,vmax=2000)
map = ax.pcolormesh(X,Y,Z, cmap='rainbow', norm=norm)
#
sm = ScalarMappable(cmap='rainbow', norm=norm)
sm.set_clim(-500,2000)
pp = fig.colorbar(sm,orientation='horizontal')
#----------------------------------------------------
#1.Background drawing: Same as above / omitted
plt.show()
Create a contour diagram from the above mesh data and display it in layers.
# (Module import): Same as above / omitted
# (Data reading ⇒ X,Y,Z):abridgement
fig, ax = plt.subplots()
#2.Color mesh drawing: Same as above / omitted
#--3.Contour drawing-----------------------------------
cont=ax.contour(X,Y,Z, 100, colors=['purple'])
#----------------------------------------------------
#1.Background drawing: Same as above / omitted
plt.show()
Finally, overlay the vector diagram. The vector is the slope of the terrain.
# (Module import): Same as above / omitted
# (Data reading ⇒ X,Y,Z):abridgement
fig, ax = plt.subplots()
#2.Color mesh drawing: Same as above / omitted
#3.Contour diagram drawing: Same as above / omitted
cont=ax.contour(X,Y,Z, 100, colors=['purple'])
#--4.Vector diagram drawing-----------------------------------
# (Vector definition ⇒ U,V):abridgement
vect=ax.quiver(X,Y,U,V,color='grey',angles='xy',scale_units='xy', scale=0.0001)
ax.quiverkey(vect,0.0,1.1,1.0,'slope')
#----------------------------------------------------
#1.Background drawing: Same as above / omitted
plt.show()
Recommended Posts