【发布时间】:2016-04-19 14:52:18
【问题描述】:
我正在尝试在等高线图上添加阴影(如点、散列、..)。这种影线可以代表唯一具有统计意义的等高线,或具有某些标准的等高线。如下图自然文章(第二和第三个情节)http://www.nature.com/articles/srep16853/figures/3。
以下代码显示来自 NOAA 数据available 的降水图,供下载。
import numpy as np
import sys
import netCDF4 as nc
import matplotlib.pyplot as plt
import matplotlib.mlab as m
import mpl_toolkits.basemap as bm
import os
sys.path.insert(0, '../');import py4met as sm;reload(sm)
#- Reading data for a timeslice, latitude, and longitude:
diri_output="./"
diri="./"
tmp_file = nc.Dataset(diri+"precip.mon.mean.nc","r")
print(tmp_file.variables)
p_pre = tmp_file.variables['precip']
lat = tmp_file.variables['lat'][:]
lon = tmp_file.variables['lon'][:]
time = tmp_file.variables['time']
tmp_file.close
lat1=np.min(lat)
lat2=np.max(lat)
lon1=np.min(lon)
lon2=np.max(lon)
[lonall, latall] = np.meshgrid(lon[:], lat[:])
plt.figure(num=None, figsize=(8+4, 6+4), dpi=80, facecolor='w', edgecolor='k')
mapproj = bm.Basemap(projection='cyl',llcrnrlat=lat1, llcrnrlon=lon1,urcrnrlat=lat2, urcrnrlon=lon2,resolution='l')
mapproj.drawcoastlines()
mapproj.drawmapboundary(fill_color='white')
mapproj.drawcountries()
x, y = mapproj(lonall, latall)
plt.contourf(x,y,p_pre[240,:,:],cmap=plt.cm.GnBu)
plt.colorbar(orientation='horizontal',pad=0.05,shrink=0.6)
plt.title("title")
xx,yy=np.where(p_pre[240,:,:] >= 20)
sig=np.copy(p_pre[0,:,:])
sig[:,:]=1
sig[xx,yy]=0
#plt.contourf(x,y,sig,hatches=['.'])
plt.show()
我想对20毫米以上的所有轮廓进行孵化,所以我使用了上面的命令
plt.contourf(x,y,sig,hatches=['.'])
但它没有用(它在地图上的任何地方都画了点,而不仅仅是具有特定标准的轮廓),因此我评论了它。 任何想法。
【问题讨论】:
标签: python matplotlib statistics contour anova