On 7/15/11 12:55 PM, Benjamin Root wrote:
On Fri, Jul 15, 2011 at 1:44 PM, Yoshi Rokuko <yo...@rokuko.net
<mailto:yo...@rokuko.net>> wrote:
+--------------------------------------------- Jeff Whitaker
-----------+
> On 7/14/11 2:25 PM, Yoshi Rokuko wrote:
> > hi, is it possible to restrict a contour plot to a
> > country? if i grid my data to projection coordinates
> > and then make a contour plot i can draw the country
> > borders on top, but since the data plotted outside
> > the country is a gridding artifact i would rather
> > not plot it.
>
> Yoshi: There is no mechanism for doing this. It is possible,
but you
> would need a way to create a mask for all the grid points
outside the
> country of interest, and then use this mask to create a masked
array to
> pass to contourf.
>
> -Jeff
wouldn't it be possible to create such a mask using internals from
Basemap.drawcountries() somehow?
best regards, yoshi
Jeff, I just had a thought....
Isn't the country borders drawn as Path or Polygon objects? I believe
there are some matplotlib internal functions that can be given a list
of points (such as those for a grid) and a path and it will return
which points are within the path and which are outside. One could use
that to make the mask.
Might make for a nice feature for basemap in the upcoming v1.1.0 release.
Ben Root
Ben/Yoshi: The countries are not polygons, they are line segments.
Worse yet, they are all just lumped together with no metadata (no way to
know which lines define the country you want). If you had a shapefile
with just the country of interest in it, defined as a polygon, then it's
doable You could take a look at the source code for the is_land method,
which tests to see if a given x,y point is inside any of the continent
polygons.
Let us know if you have you have the country polygon, and then I can
help you with the details.
-Jeff
--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : jeffrey.s.whita...@noaa.gov
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users