R. Mitra | 1 Nov 2009 22:47
Favicon

Contourf( )

Hi
    I am having problems with contourf(). Suppose I have two 10X30  
arrays X,Y and a corresponding Z value array.  How do I make the  
upper left to be the origin? I cannot use contour (Z,origin='upper')  
because the axis values gets messed up.

Thanks
Mitra

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
Eric Firing | 2 Nov 2009 04:26
Favicon
Gravatar

Re: Contourf( )

R. Mitra wrote:
> Hi
>     I am having problems with contourf(). Suppose I have two 10X30  
> arrays X,Y and a corresponding Z value array.  How do I make the  
> upper left to be the origin? I cannot use contour (Z,origin='upper')  
> because the axis values gets messed up.

It sounds like maybe you want to reverse the y-axis.  Try something like 
  plt.gca().invert_yaxis() after your call to contourf.

Eric

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
Ross.Wilson | 2 Nov 2009 08:07
Picon
Favicon

basemap: Mask the ocean [SEC=UNCLASSIFIED]

Listers,

I'm using basemap to plot randomly sampled values (x,y,z) through hexbin.  This produces a very nice
result. Some sample code is:
----------
import numpy as np
from numpy.random import seed
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib.mlab import griddata

ll_lat = -38.39477  # extent of area of interest
ll_lon = 144.54767
ur_lat = -37.51642
ur_lon = 145.67144

num_points = 100    # sample points

# create random sampling over the area of interest
seed(0)
data = np.ones((3, num_points))
data[0,:] *= ll_lon + np.random.random((num_points))*(ur_lon-ll_lon)
data[1,:] *= ll_lat + np.random.random((num_points))*(ur_lat-ll_lat)
data[2,:] *= np.random.random((num_points))*10000

# plot the data
fig = plt.figure()
ax = fig.add_subplot(111)
m = Basemap(projection='cyl', llcrnrlat=ll_lat, urcrnrlat=ur_lat,
            llcrnrlon=ll_lon, urcrnrlon=ur_lon, resolution='f',
(Continue reading)

Stephane Raynaud | 2 Nov 2009 10:00
Picon

Re: basemap: Mask the ocean [SEC=UNCLASSIFIED]

Ross,


one way is to mask (or remove) ocean points using the _geoslib module provided with basemap.
When you create a Basemap instance, you can retrieve all its polygons land (continents and islands) with "mymap.coastpolygons".
Thay are stored as numpy arrays, and you can convert them to _geoslib.Polygon objects :

poly = _geoslib.Polygon(N.asarray(coastalpoly).T)

Then you loop over all Polygons and all (x,y) points and test :

good_point = _geoslib.Point((x,y)).within(poly)

Thanks to this method, you can choose you optimal resolution.
You can even compute the intersection of you hexagons with coastal polygons using .intersection() and .area (instead of simply checking if the center is inside) and then reject points depending the fraction of the cell covered by land (or ocean).

On Mon, Nov 2, 2009 at 8:07 AM, <Ross.Wilson-Hfr3yBg5aTuHXe+LvDLADg@public.gmane.org> wrote:
Listers,

I'm using basemap to plot randomly sampled values (x,y,z) through hexbin.  This produces a very nice result. Some sample code is:
----------
import numpy as np
from numpy.random import seed
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib.mlab import griddata

ll_lat = -38.39477  # extent of area of interest
ll_lon = 144.54767
ur_lat = -37.51642
ur_lon = 145.67144

num_points = 100    # sample points

# create random sampling over the area of interest
seed(0)
data = np.ones((3, num_points))
data[0,:] *= ll_lon + np.random.random((num_points))*(ur_lon-ll_lon)
data[1,:] *= ll_lat + np.random.random((num_points))*(ur_lat-ll_lat)
data[2,:] *= np.random.random((num_points))*10000

# plot the data
fig = plt.figure()
ax = fig.add_subplot(111)
m = Basemap(projection='cyl', llcrnrlat=ll_lat, urcrnrlat=ur_lat,
           llcrnrlon=ll_lon, urcrnrlon=ur_lon, resolution='f',
           suppress_ticks=False, area_thresh=0.5)
plt.hexbin(data[0,:], data[1,:], data[2,:], zorder=3)
m.fillcontinents(color=(0.8,0.8,0.8,0), zorder=1)
m.drawcoastlines(linewidth=0.25, color='k', zorder=2)
plt.show()
----------

This contrived example shows a sparse set of hexagons on both land and ocean.  I would like the hexagons over the ocean to be hidden.  I can make the ones on land disappear by changing the 'zorder' parameter of .hexbin() to 0.  However I have found no way of doing the inverse and hiding hexagons over the ocean.

Using drawlsmask() is too crude at a 5-minute resolution.

Any ideas?

Thanks,
Ross

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users



--
Stephane Raynaud
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Jeff Whitaker | 2 Nov 2009 16:52

Re: basemap: Mask the ocean [SEC=UNCLASSIFIED]

Stephane Raynaud wrote:
> Ross,
>
>
> one way is to mask (or remove) ocean points using the _geoslib module 
> provided with basemap.
> When you create a Basemap instance, you can retrieve all its polygons 
> land (continents and islands) with "mymap.coastpolygons".
> Thay are stored as numpy arrays, and you can convert them to 
> _geoslib.Polygon objects :
>
> poly = _geoslib.Polygon(N.asarray(coastalpoly).T)
>
> Then you loop over all Polygons and all (x,y) points and test :
>
> good_point = _geoslib.Point((x,y)).within(poly)
>
> Thanks to this method, you can choose you optimal resolution.
> You can even compute the intersection of you hexagons with coastal 
> polygons using .intersection() and .area (instead of simply checking 
> if the center is inside) and then reject points depending the fraction 
> of the cell covered by land (or ocean).

Following Stephane's excellent suggestion, here's a prototype Basemap 
method that checks to see if a point is on land or over water.  Ross - 
if you find it useful I'll include it in the next release.  Note that it 
will be slow for lots of points or large map regions.

-Jeff
>
> On Mon, Nov 2, 2009 at 8:07 AM, <Ross.Wilson@... 
> <mailto:Ross.Wilson@...>> wrote:
>
>     Listers,
>
>     I'm using basemap to plot randomly sampled values (x,y,z) through
>     hexbin.  This produces a very nice result. Some sample code is:
>     ----------
>     import numpy as np
>     from numpy.random import seed
>     import matplotlib.pyplot as plt
>     from mpl_toolkits.basemap import Basemap
>     from matplotlib.mlab import griddata
>
>     ll_lat = -38.39477  # extent of area of interest
>     ll_lon = 144.54767
>     ur_lat = -37.51642
>     ur_lon = 145.67144
>
>     num_points = 100    # sample points
>
>     # create random sampling over the area of interest
>     seed(0)
>     data = np.ones((3, num_points))
>     data[0,:] *= ll_lon + np.random.random((num_points))*(ur_lon-ll_lon)
>     data[1,:] *= ll_lat + np.random.random((num_points))*(ur_lat-ll_lat)
>     data[2,:] *= np.random.random((num_points))*10000
>
>     # plot the data
>     fig = plt.figure()
>     ax = fig.add_subplot(111)
>     m = Basemap(projection='cyl', llcrnrlat=ll_lat, urcrnrlat=ur_lat,
>                llcrnrlon=ll_lon, urcrnrlon=ur_lon, resolution='f',
>                suppress_ticks=False, area_thresh=0.5)
>     plt.hexbin(data[0,:], data[1,:], data[2,:], zorder=3)
>     m.fillcontinents(color=(0.8,0.8,0.8,0), zorder=1)
>     m.drawcoastlines(linewidth=0.25, color='k', zorder=2)
>     plt.show()
>     ----------
>
>     This contrived example shows a sparse set of hexagons on both land
>     and ocean.  I would like the hexagons over the ocean to be hidden.
>      I can make the ones on land disappear by changing the 'zorder'
>     parameter of .hexbin() to 0.  However I have found no way of doing
>     the inverse and hiding hexagons over the ocean.
>
>     Using drawlsmask() is too crude at a 5-minute resolution.
>
>     Any ideas?
>
>     Thanks,
>     Ross
>
>     ------------------------------------------------------------------------------
>     Come build with us! The BlackBerry(R) Developer Conference in SF, CA
>     is the only developer event you need to attend this year.
>     Jumpstart your
>     developing skills, take BlackBerry mobile applications to market
>     and stay
>     ahead of the curve. Join us from November 9 - 12, 2009. Register now!
>     http://p.sf.net/sfu/devconference
>     _______________________________________________
>     Matplotlib-users mailing list
>     Matplotlib-users@...
>     <mailto:Matplotlib-users@...>
>     https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
>
> -- 
> Stephane Raynaud
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay 
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@...
> 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  : Jeffrey.S.Whitaker@...
325 Broadway                Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg

Attachment (hexbin.py): text/x-python-script, 1594 bytes
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
R. Mitra | 2 Nov 2009 18:45
Favicon

Re: Contourf( )

Hello All
    Thanks a lot Eric.  I think I have some module missing but I  
cannot figure out what it is.  I get the following.  Any idea.  This  
started hapening after I reinstalled matplotlib.

   File "/Users/Kennel/Pythoncodes/coolingmodel.py", line 6, in <module>
     import matplotlib
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/site-packages/matplotlib/__init__.py", line 129, in <module>
     from rcsetup import defaultParams, validate_backend,  
validate_toolbar
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/site-packages/matplotlib/rcsetup.py", line 19, in <module>
     from matplotlib.colors import is_color_like
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/site-packages/matplotlib/colors.py", line 54, in <module>
     import matplotlib.cbook as cbook
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/site-packages/matplotlib/cbook.py", line 10, in <module>
     import numpy.ma as ma
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/site-packages/numpy/ma/__init__.py", line 47, in <module>
     import extras
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ 
python2.5/site-packages/numpy/ma/extras.py", line 45, in <module>
     from numpy.lib.index_tricks import AxisConcatenator
ImportError: cannot import name AxisConcatenator

The first few lines of my codes are:

from math import *
import exceptions
import pmag
import matplotlib
matplotlib.use("TkAgg")
import numpy as np
import matplotlib.pyplot as plt

Thanks a lot for all your help.

Mitra

On Nov 1, 2009, at 11:32 PM, Eric Firing wrote:

> R. Mitra wrote:
>> Hi Eric
>> from math import *
>> import matplotlib
>> matplotlib.use("TkAgg")
>> from pylab import *
>> This is very basic I know.  The above are the modules I am using.   
>> Is plt a separate module?  Thanks.
>
> With your method above, you don't need the "plt." part.  "from  
> pylab import *" is discouraged, however, except for quick  
> interactive use. For scripts, it is generally considered better  
> practice to use
>
> import matplotlib
> matplotlib.use("tkagg")
> import numpy as np
> import matplotlib.pyplot as plt
>
> pyplot is the plot-related part of the pylab namespace; or to put  
> it another way, pylab is pyplot plus numpy.
>
> See http://matplotlib.sourceforge.net/faq/usage_faq.html
>
> Eric
>
>
>
>> RM
>> On Nov 1, 2009, at 7:26 PM, Eric Firing wrote:
>>> R. Mitra wrote:
>>>> Hi
>>>>     I am having problems with contourf(). Suppose I have two  
>>>> 10X30  arrays X,Y and a corresponding Z value array.  How do I  
>>>> make the  upper left to be the origin? I cannot use contour  
>>>> (Z,origin='upper')  because the axis values gets messed up.
>>>
>>> It sounds like maybe you want to reverse the y-axis.  Try  
>>> something like  plt.gca().invert_yaxis() after your call to  
>>> contourf.
>>>
>>> Eric
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
Eric Firing | 2 Nov 2009 18:55
Favicon
Gravatar

Re: Contourf( )

R. Mitra wrote:
> Hello All
>    Thanks a lot Eric.  I think I have some module missing but I cannot 
> figure out what it is.  I get the following.  Any idea.  This started 
> hapening after I reinstalled matplotlib.

This is a numpy installation or version problem--notice that at the 
bottom of the traceback it is something from numpy that is not being 
found.  Installation of numpy and mpl on OSX seems to be subject to all 
sorts of complications, and I don't use OSX, so I will have to leave 
this for someone else on the list.

Eric

> 
>   File "/Users/Kennel/Pythoncodes/coolingmodel.py", line 6, in <module>
>     import matplotlib
>   File 
>
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/__init__.py", 
> line 129, in <module>
>     from rcsetup import defaultParams, validate_backend, validate_toolbar
>   File 
>
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/rcsetup.py", 
> line 19, in <module>
>     from matplotlib.colors import is_color_like
>   File 
>
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/colors.py", 
> line 54, in <module>
>     import matplotlib.cbook as cbook
>   File 
>
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/cbook.py", 
> line 10, in <module>
>     import numpy.ma as ma
>   File 
>
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy/ma/__init__.py", 
> line 47, in <module>
>     import extras
>   File 
>
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy/ma/extras.py", 
> line 45, in <module>
>     from numpy.lib.index_tricks import AxisConcatenator
> ImportError: cannot import name AxisConcatenator
> 
> 
> The first few lines of my codes are:
> 
> from math import *
> import exceptions
> import pmag
> import matplotlib
> matplotlib.use("TkAgg")
> import numpy as np
> import matplotlib.pyplot as plt
> 
> Thanks a lot for all your help.
> 
> Mitra
> 
> 
> On Nov 1, 2009, at 11:32 PM, Eric Firing wrote:
> 
>> R. Mitra wrote:
>>> Hi Eric
>>> from math import *
>>> import matplotlib
>>> matplotlib.use("TkAgg")
>>> from pylab import *
>>> This is very basic I know.  The above are the modules I am using.  Is 
>>> plt a separate module?  Thanks.
>>
>> With your method above, you don't need the "plt." part.  "from pylab 
>> import *" is discouraged, however, except for quick interactive use. 
>> For scripts, it is generally considered better practice to use
>>
>> import matplotlib
>> matplotlib.use("tkagg")
>> import numpy as np
>> import matplotlib.pyplot as plt
>>
>> pyplot is the plot-related part of the pylab namespace; or to put it 
>> another way, pylab is pyplot plus numpy.
>>
>> See http://matplotlib.sourceforge.net/faq/usage_faq.html
>>
>> Eric
>>
>>
>>
>>> RM
>>> On Nov 1, 2009, at 7:26 PM, Eric Firing wrote:
>>>> R. Mitra wrote:
>>>>> Hi
>>>>>     I am having problems with contourf(). Suppose I have two 10X30  
>>>>> arrays X,Y and a corresponding Z value array.  How do I make the  
>>>>> upper left to be the origin? I cannot use contour 
>>>>> (Z,origin='upper')  because the axis values gets messed up.
>>>>
>>>> It sounds like maybe you want to reverse the y-axis.  Try something 
>>>> like  plt.gca().invert_yaxis() after your call to contourf.
>>>>
>>>> Eric
>>
> 

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
R. Mitra | 2 Nov 2009 20:11
Favicon

Installing problems

Hello Again
     Since I got no replies for my last question and figuring that it  
must be a problem with numpy (as Eric pointed out) I now have running  
python 2.6.4 and numpy 1.3.0 on OSX 10.4.11.  Is there a need to  
uninstall previous matplotlib and reinstall it again?  This page  
sounds pretty complicated for me: http://matplotlib.sourceforge.net/ 
users/installing.html#build-osx?

There are multiple versions still existing on my computer.  How can I  
clean up and install the latest version?  Thank you all so much

Mitra

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
Pierre de Buyl | 2 Nov 2009 21:42
Picon
Picon
Favicon

Re: Installing problems

Hello,

> There are multiple versions still existing on my computer.  How can I
> clean up and install the latest version?  Thank you all so much
You need to check the different paths accessed by Python.
 >>> import sys
 >>> print sys.path
and remove the possible matplotib files in these paths. Typically,  
this includes /usr/lib/python2.6/site-packages, /usr/local/lib/..., / 
opt/lib/..., /sw/lib/... (on mac)

Then, download the .tar.gz file from matplotlib website, uncompress  
and in the folder run
$ python setup.py build

That command will check dependencies before building, indicating what  
is needed.

If some dependencies are not met, I suggest to use a package manager  
to install them. I use Fink on OS 10.4.11 with no problem, but I am  
still at Python 2.5 running matplotlib 1.0.svn .

Pierre

Le 2 nov. 09 à 20:11, R. Mitra a écrit :

> Hello Again
>      Since I got no replies for my last question and figuring that it
> must be a problem with numpy (as Eric pointed out) I now have running
> python 2.6.4 and numpy 1.3.0 on OSX 10.4.11.  Is there a need to
> uninstall previous matplotlib and reinstall it again?  This page
> sounds pretty complicated for me: http://matplotlib.sourceforge.net/
> users/installing.html#build-osx?
> Mitra
>
> ---------------------------------------------------------------------- 
> --------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart  
> your
> developing skills, take BlackBerry mobile applications to market  
> and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
Brendan Arnold | 2 Nov 2009 22:19
Picon
Gravatar

Drawing a single contour line

Hi there,

I can draw a single contour line in MATLAB using

contour(z, [i i])

however,

contour(z, [i, i])

using matplotlib gives an error. In fact any plot that plots a single
line (i.e. contour(z, 1)) also gives an error as follows,

TypeError: unhashable type: 'numpy.ndarray'

How do I draw a single contour line using matplotlib?

regards,

Brendan

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference

Gmane