1
votes

I am making Polar Stereographic Projection maps of some climate model outputs. For some of these data, the plot looks weird. For example, in this figure:

enter image description here

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

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

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

I am using basemap-1.0.6 with matplotlib-1.2.1 on py2.7.

1
Please include the script/code in your question, no one is happy with a file which has to be downloaded somewhere.Manuel
Please (please!) before you post, try to clean up as much of the code as possible. You'll notice you have 14 lines of import statements, but I'm positive you don't need all of them. If we have to parse out which ones are important, we will spend less time on your actual problem.Hooked
Sorry. I have simplified the code.user2502618

1 Answers

3
votes

Your Basemap object (m) also serves as the mpl axes. When plotting, you should use that instead of using 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.

enter image description here