简体   繁体   English

使用matplotlib和底图的极坐标投影的奇怪等高线图

[英]weird contour plot with polar projections using matplotlib and basemap

I am making Polar Stereographic Projection maps of some climate model outputs. 我正在制作一些气候模型输出的Polar Stereographic Projection地图。 For some of these data, the plot looks weird. 对于其中一些数据,情节看起来很奇怪。 For example, in this figure: 例如,在此图中:

在此输入图像描述

only two color contours showed up while the actual data should span much wider range. 只有两种颜色的轮廓出现,而实际数据应该跨越更宽的范围。 Furthermore, a large portion of the region should be blank since the data are masked out by netcdf module already (they are undefined). 此外,该区域的大部分应该是空白的,因为netcdf模块已经掩盖了数据(它们是未定义的)。

from netCDF4 import Dataset
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import numpy as np    
from mpl_toolkits.basemap import Basemap    
from pylab import *
fig_index=1
fig = plt.figure(num=fig_index, figsize=(12,7), facecolor='w')
fbot_levels = arange(0.05,1.0,0.05)
fname='alb.nc4'
ncfile = Dataset(fname, 'r', format='NETCDF4')
TS2=ncfile.variables['SIALB'][0]
LON=ncfile.variables['lon'][:]
LAT=ncfile.variables['lat'][:]
ncfile.close()
lon,lat=np.meshgrid(LON,LAT)
ax2 = plt.axes([0.2, 0.225, 0.6, 0.6])
meridians=[0,1,1,1]
m = Basemap(projection='spstere',lon_0=0,boundinglat=-45)
m.drawcoastlines()
x, y =m(lon,lat)
plt.contourf(x,y,TS2, fbot_levels, origin='lower')
m.drawparallels(np.arange(-90.,120.,15.),labels=[1,0,0,0]) # draw parallels
m.drawmeridians(np.arange(0.,420.,30.),labels=meridians) # draw meridians
coloraxis = [0.1, 0.1, 0.8, 0.035]
cx = fig.add_axes(coloraxis, label='m', title='K')
cbar=plt.colorbar(cax=cx,orientation='horizontal',ticks=list(fbot_levels))
plt.show()

You can find the dataset in netcdf format which is used to generate the figure here 您可以在netcdf格式中找到用于生成图形的数据集

https://dl.dropboxusercontent.com/u/45427012/alb.nc4 https://dl.dropboxusercontent.com/u/45427012/alb.nc4

I am using basemap-1.0.6 with matplotlib-1.2.1 on py2.7. 我在py2.7上使用带有matplotlib-1.2.1的basemap-1.0.6。

Your Basemap object (m) also serves as the mpl axes. 您的Basemap对象(m)也用作mpl轴。 When plotting, you should use that instead of using plt. 在绘图时,您应该使用它而不是使用plt. . So: 所以:

m.contourf(x,y,TS2, fbot_levels, origin='lower')

Stretching the levels between 0.5 and 0.9 highlights the different contours further. 拉伸0.5到0.9之间的水平突出了不同的轮廓。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM