basemap: polar stereographic projection and clabel

When I plot contours in a stereographic south pole plot with a bounding latitude and the rounded clipping

Basemap(projection='spaeqd',lat_0=-90,lon_0=180,resolution='l',boundinglat=-40,round=True)

I see that the contours are correctly cut-off but not the contour labels. They appear to be plotted according to a rectangular frame and not the rounded one (see attached figure).

Is it possible to mask the labels without having to mask the data?

This issue may be related to an older topic:
http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg02892.html
and to a more recent bugfix
https://github.com/matplotlib/basemap/pull/89
but I do not see any other clue

thanks in advance

marcello

test.png

···

--
Dr Marcello Vichi
Centro Euro-Mediterraneo sui Cambiamenti Climatici (CMCC)
Istituto Nazionale di Geofisica e Vulcanologia (INGV)
Viale Aldo Moro 44, 40127 Bologna. Italy
Tel: +39 051 3782631 Fax: +39 051 3782654
Email: marcello.vichi@...4282..., marcello.vichi@...4281...
skype: marcello_vichi

compose-unknown-contact.jpg

Marcello Vichi

February 19, 2013
7:33 AM

When I plot contours in a stereographic south pole plot with a bounding latitude and the rounded clipping

Basemap(projection=‘spaeqd’,lat_0=-90,lon_0=180,resolution=‘l’,boundinglat=-40,round=True)

I see that the contours are correctly cut-off but not the contour labels. They appear to be plotted according to a rectangular frame and not the rounded one (see attached figure).

Is it possible to mask the labels without having to mask the data?

This issue may be related to an older topic:

and to a more recent bugfix
but I do not see any other clue
thanks in advance
marcello

Marcello: I cannot reproduce your problem. From the github pull request you mention, it seems like this was fixed about 3 months ago. What version of basemap are you running?

-Jeff

···

http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg02892.html

https://github.com/matplotlib/basemap/pull/89

Thanks Jeff

this is what I have

In [1]: import matplotlib
In [2]: matplotlib.__version__
Out[2]: '1.2.0'

I also tried with a different dataset, the one from
http://matplotlib.org/basemap/users/examples.html
and I get the same problem

from mpl_toolkits.basemap import Basemap
from netCDF4 import Dataset
import numpy as np
import matplotlib.pyplot as plt
date = '20071215' # date to plot.
# open dataset for that date.
dataset = \
Dataset('http://www.ncdc.noaa.gov/thredds/dodsC/oisst/NetCDF/AVHRR-AMSR/%s/AVHRR\-AMSR/amsr\-avhrr\-v2\.%s\.nc\.gz'%
        (date[0:4],date))
# read sst. Will automatically create a masked array using
# missing_value variable attribute. 'squeeze out' singleton dimensions.
sst = dataset.variables['sst'][:].squeeze()
# read ice.
ice = dataset.variables['ice'][:].squeeze()
# read lats and lons (representing centers of grid boxes).
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]
# shift lats, lons so values represent edges of grid boxes
# (as pcolor expects).
delon = lons[1]-lons[0]; delat = lats[1]-lats[0]
lons = (lons - 0.5*delon).tolist()
lons.append(lons[-1]+delon)
lons = np.array(lons,np.float64)
lats = (lats - 0.5*delat).tolist()
lats.append(lats[-1]+delat)
lats = np.array(lats,np.float64)
# create figure, axes instances.
fig = plt.figure()
ax = fig.add_axes([0.05,0.05,0.9,0.9])
m = Basemap(projection='spaeqd',lat_0=-90,lon_0=180,resolution='l',boundinglat=-40,round=True)
x, y = m(*np.meshgrid(lons, lats))
o=m.drawcoastlines(linewidth=0.25)
o=m.drawcountries(linewidth=0.25)
o=m.fillcontinents(color="grey",lake_color='white')
o=m.drawmeridians(np.arange(0,360,30),labels=[1,1,1,1])
o=m.drawparallels(np.arange(-90,90,10),labels=[1,1,1,1])
cim=m.contour(x[:-1,:-1],y[:-1,:-1],sst,arange(2,28,2),linewidths=0.5,colors='k')
plt.clabel(cim, inline=1, fontsize=10, fmt = '%.1f',)

···

On 27/02/13 19:59, Jeff Whitaker wrote:

Marcello Vichi <mailto:marcello.vichi@…4281…>
February 19, 2013 7:33 AM
When I plot contours in a stereographic south pole plot with a
bounding latitude and the rounded clipping

Basemap(projection='spaeqd',lat_0=-90,lon_0=180,resolution='l',boundinglat=-40,round=True)

I see that the contours are correctly cut-off but not the contour
labels. They appear to be plotted according to a rectangular frame and
not the rounded one (see attached figure).

Is it possible to mask the labels without having to mask the data?

This issue may be related to an older topic:
Re: [Matplotlib-users] clabel and basemap

and to a more recent bugfix
fix for issue #88 by jswhit · Pull Request #89 · matplotlib/basemap · GitHub
but I do not see any other clue

thanks in advance

marcello

Marcello: I cannot reproduce your problem. From the github pull request
you mention, it seems like this was fixed about 3 months ago. What
version of basemap are you running?

-Jeff

--
Dr Marcello Vichi
Centro Euro-Mediterraneo sui Cambiamenti Climatici (CMCC)
Istituto Nazionale di Geofisica e Vulcanologia (INGV)
Viale Aldo Moro 44, 40127 Bologna. Italy
Tel: +39 051 3782631 Fax: +39 051 3782654
Email: marcello.vichi@...4282..., marcello.vichi@...4281...
skype: marcello_vichi

compose-unknown-contact.jpg

Marcello Vichi

February 27, 2013
1:40 PM

Thanks Jeff

this is what I have

In [1]: import matplotlib

In [2]: matplotlib.version

Out[2]: ‘1.2.0’

Marcello: I asked what version of basemap you had, not matplotlib. Anyway, thanks for providing the script - with it I can reproduce the problem. It looks like the Text instances returned by clabel are not being clipped properly. Unfortunately, I don’t have any idea why. I’ll get back to you if I find a solution.

BTW:
you don’t need to shift the lons and lats to represent the center of the gridbox (that’s only needed for pcolor).

-Jeff

···

http://matplotlib.org/basemap/users/examples.html

http://www.ncdc.noaa.gov/thredds/dodsC/oisst/NetCDF/AVHRR-AMSR/%s/AVHRR-AMSR/amsr-avhrr-v2.%s.nc.gz’%

http://p.sf.net/sfu/appdyn_d2d_febMatplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg02892.html

https://github.com/matplotlib/basemap/pull/89


Everyone
hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:

http://p.sf.net/sfu/appdyn_d2d_feb


Matplotlib-users
mailing list

Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users



Jeffrey S. Whitaker Phone : (303)497-6313

Meteorologist
FAX : (303)497-6449

NOAA/OAR/PSD R/PSD1 Email : 325 Broadway
Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web :

Jeffrey.S.Whitaker@…259…

http://tinyurl.com/5telg

compose-unknown-contact.jpg

Marcello Vichi

February 27, 2013
1:40 PM

Thanks Jeff

this is what I have

In [1]: import matplotlib

In [2]: matplotlib.version

Out[2]: ‘1.2.0’

Marcello: As a workaround you could mask the data outside the bounding lat of the projection before you draw the contour lines. Something like this ought to do it:

from numpy import ma
sst = ma.masked_array(sst, mask=lats>-40)

-Jeff

···

http://matplotlib.org/basemap/users/examples.html

http://www.ncdc.noaa.gov/thredds/dodsC/oisst/NetCDF/AVHRR-AMSR/%s/AVHRR-AMSR/amsr-avhrr-v2.%s.nc.gz’%

http://p.sf.net/sfu/appdyn_d2d_febMatplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg02892.html

https://github.com/matplotlib/basemap/pull/89


Everyone
hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:

http://p.sf.net/sfu/appdyn_d2d_feb


Matplotlib-users
mailing list

Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users



Jeffrey S. Whitaker Phone : (303)497-6313

Meteorologist
FAX : (303)497-6449

NOAA/OAR/PSD R/PSD1 Email : 325 Broadway
Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web :

Jeffrey.S.Whitaker@…259…

http://tinyurl.com/5telg