From: Marcello V. <mar...@bo...> - 2013-02-19 14:33:44
Attachments:
test.png
|
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/mat...@li.../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 -- 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: mar...@cm..., mar...@bo... skype: marcello_vichi |
From: Jeff W. <jef...@no...> - 2013-02-27 19:01:48
|
> Marcello Vichi <mailto:mar...@bo...> > 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: > http://www.mail-archive.com/mat...@li.../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 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 |
From: Marcello V. <mar...@bo...> - 2013-02-27 20:41:32
|
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:mar...@bo...> >> 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: >> http://www.mail-archive.com/mat...@li.../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 > 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: mar...@cm..., mar...@bo... skype: marcello_vichi |
From: Jeff W. - N. F. <jef...@no...> - 2013-02-27 21:07:55
|
> Marcello Vichi <mailto:mar...@bo...> > 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 > > 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',) > > > > > Jeff Whitaker <mailto:jef...@no...> > February 27, 2013 11:59 AM > > > 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 > ------------------------------------------------------------------------------ > 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 > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > Marcello Vichi <mailto:mar...@bo...> > 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: > http://www.mail-archive.com/mat...@li.../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 > > ------------------------------------------------------------------------------ > 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 > Mat...@li... > 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 : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |
From: Jeff W. - N. F. <jef...@no...> - 2013-02-27 21:13:39
|
> Marcello Vichi <mailto:mar...@bo...> > 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 > > 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',) > > > > > Jeff Whitaker <mailto:jef...@no...> > February 27, 2013 11:59 AM > > > 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 > ------------------------------------------------------------------------------ > 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 > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > Marcello Vichi <mailto:mar...@bo...> > 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: > http://www.mail-archive.com/mat...@li.../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 > > ------------------------------------------------------------------------------ > 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 > Mat...@li... > 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 : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |