Contour Labels not showing up
Asked Answered
C

1

6

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:

problem

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]
Content answered 3/6, 2015 at 6:19 Comment(2)
I can appreciate that the raw data might be under a licensing agreement or something - but some representative approximation of x,y and plotted_var would be useful to be able to test / replicate this.Saddlecloth
The input data is standard GFS meteorological data. I'll edit the post with some representations of the data.Content
C
4

I seem to have resolved the issue like so:

resolved issue

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.

Content answered 3/6, 2015 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.