In Visual Studio Code python3 using the contour mapping matplotlib

Configuring Python development environment

Install python

Remember to check the add environment variables. Add Python to PATH
Here Insert Picture DescriptionHere Insert Picture Description

import this

Zen enjoy under the python
Here Insert Picture Description

Download and install third-party packages

pip install flake8
pip install yapf

Check whether the package needs already exists

pip list

Placed Visual Studio Code

user settings

Visual Studio Code File -> Preferences -> Settings -> User Configuration settings.json

"python.pythonPath": "python3",

Set the work area

Enter the following work areas:

{
    "python.linting.flake8Enabled": true,
    "python.formatting.provider": "yapf",
    "python.linting.flake8Args": ["--max-line-length=248"],
    "python.linting.pylintEnabled": false
}

matplotlib

Installation matplotlib

python -m pip install matplotlib

Test Run matplotlib

Run the test program:

import numpy as np
from matplotlib import pyplot as plt

x = np.arange(1, 11)
y = 2 * x + 5
plt.title("Matplotlib demo")
plt.xlabel("x axis caption")
plt.ylabel("y axis caption")
plt.plot(x, y)
plt.show()

Here Insert Picture Description

basemap

Installation geos

pip install geos

Installation basemap

basemap can not use pip install

Access https://www.lfd.uci.edu/~gohlke/pythonlibs/

Here Insert Picture DescriptionBasemap selected, according to their own choice installed version of Python, 32 and 64 is the version of Python installed behind the Python version number cp.
Here Insert Picture Description
You need to download the page pyproj, pyhdf, netCDF4 corresponding package in the current whl

pip install pyproj-2.4.0-cp37-cp37m-win_amd64.whl
pip install pyhdf-0.10.1-cp37-cp37m-win_amd64.whl
pip install basemap-1.2.1-cp37-cp37m-win_amd64.whl
pip install netCDF4-1.5.3-cp37-cp37m-win_amd64.whl

Here Insert Picture Description

Test Run basemap

Run the test program:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
plt.figure(figsize=(16, 8))
m = Basemap()
m.drawcoastlines()
m.drawcountries(linewidth=1.5)
plt.show()

Here Insert Picture Description

run

Reference https://matplotlib.org/basemap/users/examples.html

We use the first example: Plot contour lines on a basemap (contour lines drawn on a map)

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
# set up orthographic map projection with
# perspective of satellite looking down at 50N, 100W.
# use low resolution coastlines.
map = Basemap(projection='ortho',lat_0=45,lon_0=-100,resolution='l')
# draw coastlines, country boundaries, fill continents.
map.drawcoastlines(linewidth=0.25)
map.drawcountries(linewidth=0.25)
map.fillcontinents(color='coral',lake_color='aqua')
# draw the edge of the map projection region (the projection limb)
map.drawmapboundary(fill_color='aqua')
# draw lat/lon grid lines every 30 degrees.
map.drawmeridians(np.arange(0,360,30))
map.drawparallels(np.arange(-90,90,30))
# make up some data on a regular lat/lon grid.
nlats = 73; nlons = 145; delta = 2.*np.pi/(nlons-1)
lats = (0.5*np.pi-delta*np.indices((nlats,nlons))[0,:,:])
lons = (delta*np.indices((nlats,nlons))[1,:,:])
wave = 0.75*(np.sin(2.*lats)**8*np.cos(4.*lons))
mean = 0.5*np.cos(2.*lats)*((np.sin(2.*lats))**2 + 2.)
# compute native map projection coordinates of lat/lon grid.
x, y = map(lons*180./np.pi, lats*180./np.pi)
# contour data over the map.
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
plt.title('contour lines over filled continent background')
plt.show()

Here Insert Picture Description

Published 72 original articles · won praise 66 · Views 150,000 +

Guess you like

Origin blog.csdn.net/miaodichiyou/article/details/102783818
Recommended