I am trying to overlay contours on top of a filled contour plot in matplotlib for some atmospheric data. However, my contour labels are not always showing up onscreen. Below is an example:
As you can see, the contour labels are only appearing on the innermost few contours.
Knowing that my contour range is defined earlier as
list(range(950,1052,4))
I have the following code to actually plot:
parallels = np.arange(0.,90,5.)
basem.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
# draw meridians
meridians = np.arange(180.,360.,5.)
basem.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
basem.drawstates()
basem.drawcountries()
if clevs != 0:
cs = basem.contourf(x,y, plotted_var, clevs)
cl = basem.contour(x,y, plotted_var, clevsl, colors='k')
plt.clabel(cl, fmt="%1.0f", fontsize=8)
else:
cs = basem.contourf(x,y, plotted_var, cmap=plt.get_cmap(colorbar),
vmin = vmin, vmax = vmax)
cbar = basem.colorbar(cs, location='bottom', pad = "5%")
cbar.set_label(units)
Additionally, my basemap definition is:
basem = Basemap(width=5800000,height=3000000,
rsphere=(6378137.00,6356752.3142),\
resolution='h',area_thresh=1000.,projection='lcc',\
lat_1=45.,lat_2=55,lat_0=40,lon_0=-102.)
Is this a bug or is there just something I'm missing? I'm attempting to avoid the use of manual if I can.
The input data is a global dataset (GFS weather model). x, y are obtained by:
lons2, lats2 = np.meshgrid(lons, lats)
x,y = basem(lons2, lats2)
where lons, lats are:
lons = [0.0, 0.25, 0.5, 0.75, 1.0, ..., 359.75, 360.0]
lats = [-90, -89.75, ..., 89.75, 90]
Click Annotate tab > Labels & Tables panel > Add Labels menu > Surface > Contour - Multiple. Select the contours to label by specifying the start and end points of the contour label line. Press Enter.
I seem to have resolved the issue like so:
What I had to do was bound the data to what is able to be seen on basemap. My input dataset was a global dataset, and when I bound it (seen in the white areas below), the contour labels showed up mostly within the map boundaries. This still seems like a bug- my choice of a display region changes the locations of the contour labels in almost every other meteorological graphics program (like GrADS), but I'm going to mark this answered for now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With