read_netCDF.py
import matplotlib as mp
import numpy as np
ind='hoge.grd'
Dat = np.netcdf(ind,'r').variables['z'][::-1]
lon=np.netcdf(ind,'r').variables['x'][::-1]
lat=np.netcdf(ind,'r').variables['y'][::-1]
NX, NY=np.meshgrid(lon, lat)
#The center of the color bar while specifying the minimum and maximum values of the color bar(z=0)The color of is maintained.
norm = mp.colors.TwoSlopeNorm(vcenter=0.0, vmin=-0.2, vmax=0.1)
#Cut out a part of 2D data[pixel]
extX0=950
extX1=1600
extY0=1100
extY1=1750
#Also specify figure size
fig=plt.figure(figsize=(10,10))
#jet colormap
plt.pcolormesh(NX[extY0:extY1, extX0:extX1], NY[extY0:extY1, extX0:extX1], Dat[extY0:extY1, extX0:extX1], cmap='jet', norm=norm)
plt.colorbar() #Color bar display
plt.xlabel('Longitude [deg.]')
plt.ylabel('Latitude [deg.]')
plt.show()
A figure like this is displayed ↓
Recommended Posts