Overlay background diagram, contour diagram, vector diagram with python

Thing you want to do

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.

Background view

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()

Color contour diagram

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()

Contour diagram

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()

Vector illustration

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

Overlay background diagram, contour diagram, vector diagram with python
Let Heroku do background processing with Python
Create a frame with transparent background with tkinter [Python]
Statistics with python
[python] vector operation
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
Image processing from scratch with python (4) Contour extraction
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Fill the background with a single color with OpenCV2 + Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Scraping with Python (preparation)
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA
Handling yaml with python
Serial communication with python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
Run prepDE.py with python3
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Kernel Method with Python
Non-blocking with Python + uWSGI
Scraping with Python + PhantomJS
Posting tweets with python
Drive WebDriver with python
Use mecab with Python3
[Python] Redirect with CGIHTTPServer
Voice analysis with python
Think yaml with python
Operate Kinesis with Python
Getting Started with Python
Use DynamoDB with Python
Zundko getter with python
Handle Excel with python
Ohm's Law with Python
Primality test with python
Run Blender with python
Solve Sudoku with Python
Python starting with Windows 7
Heatmap with Python + matplotlib
Multi-process asynchronously with python
Learning Python with ChemTHEATER 02