Re: [Matplotlib-users] Polygon masking possible?

2008-03-11 Thread Jae-Joon Lee
Hi,

I often do this with ds9 and funtools.
ds9 is an astronomy-oriented image viewer (http://hea-www.harvard.edu/RD/ds9/)
but you can also use it with numpy array.
Within ds9, you can define regions (ellipse, polynomial, etc) easily
with a mouse.
After you define a region (and save it as a file), you can convert it
to a mask image
with funtools (funtools is a name of an astronomy-oriented image
utility pacakge).
funtools only support fits file (image format in astronomy) so this
can be a bit tricky, but if you're
interested i'll send my python wrapper code for it.

So, take a look at ds9 and see it fits your need.
To view numpy array in ds9,
  *. From python, save the array as a file (tofile method, better use
"arr" as an extension)
  * in ds9, file-> open others -> open array. You need to select
array dimension, type and  endianness of the array.

Regards,

-JJ





On Sat, Mar 8, 2008 at 11:17 AM, Chiara Caronna
<[EMAIL PROTECTED]> wrote:
>
>  Hello,
> I am also interested in masking polygons and defining the polygon by
> 'clicking' on the image... but I do not know anything about GUI does
> anyone can help? Is there already something implemented?
> Thanks!
> Chiara
>
> > Date: Wed, 23 Jan 2008 13:50:15 +1300
> > From: [EMAIL PROTECTED]
> > To: matplotlib-users@lists.sourceforge.net
> > Subject: Re: [Matplotlib-users] Polygon masking possible?
>
>
> >
> > Hi Søren,
> >
> > I've put this back on the list in case it's useful to anyone else, or
> > if there are better suggestions or improvements around. Hope you don't
> > mind.
> >
> > On 22/01/2008, Søren Nielsen <[EMAIL PROTECTED]> wrote:
> > > Yeah i'd like to see your code if I can..
> >
> > import numpy as n
> >
> > def get_poly_pts(x, y, shape):
> > """Creates convex polygon mask from list of corners.
> >
> > Parameters
> > --
> > x : array_like
> > x co-ordinates of corners
> > y : array_like
> > y co-ordinates of corners, in order corresponding to x
> > shape : array_like
> > dimension sizes of result
> >
> > Returns
> > ---
> > build : ndarray
> > 2-D array of shape shape with values True inside polygon
> >
> > Notes
> > -
> > Code is constrained to convex polygons by "inside"
> > assessment criterion.
> >
> > """
> > x = n.asarray(x)
> > y = n.asarray(y)
> > shape = n.asarray(shape)
> > npts = x.size # should probably assert x.size == y.size
> > inds = n.indices( shape )
> > xs = inds[0]
> > ys = inds[1]
> > xav = n.round(x.mean()).astype(int)
> > yav = n.round(y.mean()).astype(int)
> > for i in xrange(npts): # iterate over pairs of co-ordinates
> > j = (i + 1) % npts
> > m = (y[j] - y[i])/(x[j] - x[i])
> > c = (x[j] * y[i] - x[i] * y[j])/(x[j] - x[i])
> > thisone = ( ys > m * xs + c )
> > if thisone[xav, yav] == False:
> > thisone = ~thisone
> > if i == 0:
> > build = thisone
> > else:
> > build &= thisone
> > return build
> >
> > (released under BSD licence)
> >
> > > I just needed the push over the edge to know how to draw on the canvas,
> > > mapping clicks etc. since i'm still fairly new to matplotlib, so I think
> > > your code will be helpfull.
> >
> > I hope so. As you can see this code doesn't do any of the drawing or
> > click collecting, but the cookbook page should be able to guide you
> > there. Ask again on the list if you have any further questions and
> > we'll see if we can help.
> >
> > Also, the code assumes that the average co-ordinate is inside the
> > shape - that's true for convex polygons, but not necessarily for
> > arbitrary ones. I use if after taking a convex hull of a greater list
> > of points (using the delaunay module in scipy (now in scikits, I
> > hear)), which ensures convexity. You just need to be aware of that
> > limitation.
> >
> > Cheers,
> >
> > A.
> > --
> > AJC McMorland, PhD candidate
> > Physiology, University of Auckland
> >
> > -
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
> > ___
> > Matplotlib-users mailing list
> > Matplotlib-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
> 
> Express yourself instantly with MSN Messenger! MSN Messenger
> -
>  This SF.net email is sponsored by: Microsoft
>  Defy all challenges. Microsoft(R) Visual Studio 2008.
>  http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
> ___
>  Matplotlib-users mailing list
>  Matplotlib-users@lists.sourceforge.net
>  https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0

Re: [Matplotlib-users] Major Issue with 0.91.2 and Python-2.5

2008-03-11 Thread Jouni . Seppanen
Rich Shepard <[EMAIL PROTECTED]> writes:

> On Tue, 11 Mar 2008, Michael Droettboom wrote:
>> I would first try to track down which font file it is, and then send it to 
>> me 
>> off list and I'll have a look at what might be tripping up matplotlib.
>
> I'm not sure that I know which font file is the problem. 
[...]
>File "/usr/lib/python2.5/site-packages/matplotlib/afm.py", line 282, in 
> parse_afm
>  dcmetrics_ascii, dcmetrics_name = _parse_char_metrics(fh)
>File "/usr/lib/python2.5/site-packages/matplotlib/afm.py", line 166, in 
> _parse_char_metrics
>  name = vals[2].split()[1]
> IndexError: list index out of range

Try this to debug the problem:

python -i your-script.py
 (wait for the traceback)
>>> from pdb import pm
>>> pm()
(Pdb) p vals
(Pdb) up
(Pdb) p fh

The command "p fh" should show the name of the font file. You can exit
the debugger with Ctrl-D, or type "help" to see all the commands if you
wish to explore the problem further.

You need to write the "from pdb import pm" and "pm()" lines carefully,
because if any typo causes another traceback, the previous one is
forgotten.

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] variable line thickness in a plot

2008-03-11 Thread Steve Schmerler
On Tue, Mar 11, 2008 at 01:23:55PM -0700, eliss wrote:
> On 3/11/08, Steve Schmerler <[EMAIL PROTECTED]> wrote:
> >
> > On Tue, Mar 11, 2008 at 12:45:21PM -0700, eliss wrote:
> > > The API for the plot function states that the line thickness can only be
> > a
> > > single floating point number.
> > >
> >
> > Really? Try
> >
> >plot([1,2,3], lw=math.pi)
> >
> > cheers,
> > steve
> 
> 
> Sorry, I don't get your point. math.pi is just a single floating point
> number. How can I use that to create lines with variable thickness?

Ah sorry for the noise, I didn't read your message well. I somehow thought you
ment an *integer* rather than a float. 

So, I'm not sure whether you want a single line that changes width and color or 
several lines that change. In the latter case you could of course just loop over
your properties. Something like

x = linspace(0,3,50)
for w in [0,1,2,3,4,5]: 
plot(x, sin(x*w), lw=w, color=(w/5.0,0,(5-w)/5.0));

If you don't want that, then the example from Troels Kofoed Jacobsen will be
a nice way to go. Didn't know about mlab.poly_between. Didn't find it in the 
CHANGELOG.

cheers,
steve

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Major Issue with 0.91.2 and Python-2.5

2008-03-11 Thread Rich Shepard
On Tue, 11 Mar 2008, Michael Droettboom wrote:

> I suspect there is an .afm font file on your new system that is untested with 
> matplotlib and exhibiting something "new".
>
> I would first try to track down which font file it is, and then send it to me 
> off list and I'll have a look at what might be tripping up matplotlib.

Mike,

   I'm not sure that I know which font file is the problem. Here's the output
from trying to run my application on python-2.5 (the top two lines are
repeated many times before we get to the traceback):

Found an unknown keyword in AFM header (was Underline)
Found an unknown keyword in AFM header (was Underline)
Traceback (most recent call last):
   File "eikos.py", line 3, in 
 import wx, serial, os, config, functions
   File "/home/rshepard/projects/eikos/functions.py", line 7, in 
 import pylab as p
   File "/usr/lib/python2.5/site-packages/pylab.py", line 1, in 
 from matplotlib.pylab import *
   File "/usr/lib/python2.5/site-packages/matplotlib/pylab.py", line 208, in 

 from matplotlib import mpl  # pulls in most modules
   File "/usr/lib/python2.5/site-packages/matplotlib/mpl.py", line 3, in 

 from matplotlib import axis
   File "/usr/lib/python2.5/site-packages/matplotlib/axis.py", line 20, in 

 from font_manager import FontProperties
   File "/usr/lib/python2.5/site-packages/matplotlib/font_manager.py", line 
1132, in 
 _rebuild()
   File "/usr/lib/python2.5/site-packages/matplotlib/font_manager.py", line 
1123, in _rebuild
 fontManager = FontManager()
   File "/usr/lib/python2.5/site-packages/matplotlib/font_manager.py", line 
913, in __init__
 self.afmdict = createFontDict(self.afmfiles, fontext='afm')
   File "/usr/lib/python2.5/site-packages/matplotlib/font_manager.py", line 
512, in createFontDict
 font = afm.AFM(fh)
   File "/usr/lib/python2.5/site-packages/matplotlib/afm.py", line 294, in 
__init__
 parse_afm(fh)
   File "/usr/lib/python2.5/site-packages/matplotlib/afm.py", line 282, in 
parse_afm
 dcmetrics_ascii, dcmetrics_name = _parse_char_metrics(fh)
   File "/usr/lib/python2.5/site-packages/matplotlib/afm.py", line 166, in 
_parse_char_metrics
 name = vals[2].split()[1]
IndexError: list index out of range

   If it's relevant to the issue, I no longer have ~/.matplotlib/fonts.cache as 
someone
suggested yesterday that I delete it, and it's not been regenerated.

Thanks,

Rich

-- 
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
 Voice: 503-667-4517  Fax: 503-667-8863

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] variable line thickness in a plot

2008-03-11 Thread eliss
On 3/11/08, Troels Kofoed Jacobsen <[EMAIL PROTECTED]> wrote:
>
> On Tue, Mar 11, 2008 at 01:23:04PM -0700, eliss wrote:
> >
> >On 3/11/08, Troels Kofoed Jacobsen <[EMAIL PROTECTED]> wrote:
> >
> >  On Tue, Mar 11, 2008 at 12:45:21PM -0700, eliss wrote:
> >  >
> >  >Hi, does anyone know of a way to create lines with variable
> >  thickness
> >  >and color when doing a plot?
> >  >Basically, I'd like to have a third dimension represented
> using
> >  >thickness. The API for the plot function states that the line
> >  thickness
> >  >can only be a single floating point number.
> >  >Thanks
> >  I don't know if this is the easiest way, but it can be done with
> >  clever use of fill:
> >  from pylab import *
> >  x = linspace(0,10,101)
> >  y = cos(x)
> >  z = sin(3*x)+2
> >  zn = 0.05*z
> >  xs, ys = mlab.poly_between(x, y-zn, y+zn)
> >  fill(xs, ys)
> >  show()
> >  Best Regards
> >
> >
> >Thanks for the reply. I couldn't find the "poly_between" function in
> >mlab. I imported my mlab, and did dir(mlab) but that method doesn't
> >show up in there. I tried redownloading the latest version of
> >matplotlib as well. Am I missing a library?
> >
> > References
> >
> >1. mailto:[EMAIL PROTECTED]
>
> >
> -
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
> > ___
> > Matplotlib-users mailing list
> > Matplotlib-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
> I have version 0.91.2 of matplotlib and for me the function is there.
>
> (I found it in the fill_between.py example)


Ah, my os did not have the latest package in the repository so I had to
build it. Works now. Thanks!
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] variable line thickness in a plot

2008-03-11 Thread Troels Kofoed Jacobsen
On Tue, Mar 11, 2008 at 01:23:04PM -0700, eliss wrote:
> 
>On 3/11/08, Troels Kofoed Jacobsen <[EMAIL PROTECTED]> wrote:
> 
>  On Tue, Mar 11, 2008 at 12:45:21PM -0700, eliss wrote:
>  >
>  >Hi, does anyone know of a way to create lines with variable
>  thickness
>  >and color when doing a plot?
>  >Basically, I'd like to have a third dimension represented using
>  >thickness. The API for the plot function states that the line
>  thickness
>  >can only be a single floating point number.
>  >Thanks
>  I don't know if this is the easiest way, but it can be done with
>  clever use of fill:
>  from pylab import *
>  x = linspace(0,10,101)
>  y = cos(x)
>  z = sin(3*x)+2
>  zn = 0.05*z
>  xs, ys = mlab.poly_between(x, y-zn, y+zn)
>  fill(xs, ys)
>  show()
>  Best Regards
> 
> 
>Thanks for the reply. I couldn't find the "poly_between" function in
>mlab. I imported my mlab, and did dir(mlab) but that method doesn't
>show up in there. I tried redownloading the latest version of
>matplotlib as well. Am I missing a library?
> 
> References
> 
>1. mailto:[EMAIL PROTECTED]

> -
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I have version 0.91.2 of matplotlib and for me the function is there.

(I found it in the fill_between.py example)


-- 
Troels Kofoed Jacobsen
[EMAIL PROTECTED]
tel: +45 20880798

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] variable line thickness in a plot

2008-03-11 Thread eliss
On 3/11/08, Troels Kofoed Jacobsen <[EMAIL PROTECTED]> wrote:
>
> On Tue, Mar 11, 2008 at 12:45:21PM -0700, eliss wrote:
> >
> >Hi, does anyone know of a way to create lines with variable thickness
> >and color when doing a plot?
> >Basically, I'd like to have a third dimension represented using
> >thickness. The API for the plot function states that the line
> thickness
> >can only be a single floating point number.
> >Thanks
>
> I don't know if this is the easiest way, but it can be done with clever
> use of fill:
>
> from pylab import *
>
> x = linspace(0,10,101)
> y = cos(x)
> z = sin(3*x)+2
> zn = 0.05*z
>
> xs, ys = mlab.poly_between(x, y-zn, y+zn)
> fill(xs, ys)
> show()
>
> Best Regards


Thanks for the reply. I couldn't find the "poly_between" function in mlab. I
imported my mlab, and did dir(mlab) but that method doesn't show up in
there. I tried redownloading the latest version of matplotlib as well. Am I
missing a library?
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] variable line thickness in a plot

2008-03-11 Thread Steve Schmerler
On Tue, Mar 11, 2008 at 12:45:21PM -0700, eliss wrote:
> The API for the plot function states that the line thickness can only be a
> single floating point number.
> 

Really? Try

plot([1,2,3], lw=math.pi)

cheers,
steve

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] variable line thickness in a plot

2008-03-11 Thread Troels Kofoed Jacobsen
On Tue, Mar 11, 2008 at 12:45:21PM -0700, eliss wrote:
> 
>Hi, does anyone know of a way to create lines with variable thickness
>and color when doing a plot?
>Basically, I'd like to have a third dimension represented using
>thickness. The API for the plot function states that the line thickness
>can only be a single floating point number.
>Thanks

> -
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I don't know if this is the easiest way, but it can be done with clever use of 
fill:

from pylab import *

x = linspace(0,10,101)
y = cos(x)
z = sin(3*x)+2
zn = 0.05*z

xs, ys = mlab.poly_between(x, y-zn, y+zn)
fill(xs, ys)
show()

Best Regards

-- 
Troels Kofoed Jacobsen
[EMAIL PROTECTED]
tel: +45 20880798

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] variable line thickness in a plot

2008-03-11 Thread eliss
Hi, does anyone know of a way to create lines with variable thickness and
color when doing a plot?

Basically, I'd like to have a third dimension represented using thickness.
The API for the plot function states that the line thickness can only be a
single floating point number.

Thanks
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [newbie] "live" plots of multiple lines

2008-03-11 Thread Chris Withers
Chris Withers wrote:
> Matthias Michler wrote:
>> plot([x1], [y1], "bo", [x2], [y2], "r+")
> 
> This didn't work :-S
> 
> - the first time I call show(), execution never comes back to my script 
> so the code never gets to plot any further points

Okay, thanks to Ryan, I now have this point fixed, however, with the 
following code:

ion()
i = 1
while i < 5:
 plot([i],[i],'go',[i],[i+2],'ro')
 print i
 i+=1
 sleep(0.5)
 draw()

- there are no lines between the points, how do I get the lines to show?

- how would I pass keyword parameters such as "label" or use other 
methods such as plot_date?

Also, when the above script finishes, I get:

Fatal Python error: PyEval_RestoreThread: NULL tstate

This application has requested the Runtime to terminate it in an unusual 
way.
Please contact the application's support team for more information.

What does that mean?

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] pcolor and

2008-03-11 Thread Jeff Whitaker
mbauer wrote:
> Matplotlib users,
>
> I've been using pcolor and pcolormesh to plot results from the NCEP  
> Reanalysis. I've noticed that the plotted values are slightly offset.  
> Googling around I see that matlab has this quality, which I assume  
> matplotlib inherited.
>
>  # If your georeferenced image is in lat/long coordinates (i.e.  
> each data row is along a line of
>constant latitude, each column a line of equal longitude), ...  
> you MUST remember to offset your
>coordinates by one-half of the pixel spacing. This is because  
> of the different behaviors of
>p_color and image when given the same data.
>   1. image will center the drawn (i,j) pixel on the (i,j)th entry of  
> the X/Y matrices.
>   2. p_color with shading flat will draw a panel between the (i,j), 
> (i+1,j),(i+1,j+1),(i,j+1)
>  coordinates of the X/Y matrices with a color corresponding to  
> the data value at (i,j). Thus
>  everything will appear shifted by one half a pixel spacing.
>
> and
>   % Since the grid is rectangluar in lat/long (i.e. not
>   % really a projection at all, althouhg it is included in
>   % m_map under the name 'equidistant cyldindrical'), we
>   % don't want to use the 'image' technique. Instead...
>   % Create a grid, offsetting by half a grid point to account
>   % for the flat pcolor
>   [Plg,Plt]=meshgrid(Plon-0.25,Plat+0.25);
>
> The data I'm using uses polar grids centered on +-90.0 which give a  
> latitude array as such
> [-90.  -87.5 -85.  -82.5 -80.  -77.5 -75.  -72.5 -70.  -67.5 -65.  -62.5
>   -60.  -57.5 -55.  -52.5 -50.  -47.5 -45.  -42.5 -40.  -37.5 -35.   
> -32.5
>   -30.  -27.5 -25.  -22.5 -20.  -17.5 -15.  -12.5 -10.   -7.5  -5.
> -2.5
> 0.2.5   5.7.5  10.   12.5  15.   17.5  20.   22.5  25.
> 27.5
>30.   32.5  35.   37.5  40.   42.5  45.   47.5  50.   52.5  55.
> 57.5
>60.   62.5  65.   67.5  70.   72.5  75.   77.5  80.   82.5  85.
> 87.5
>90. ]
>
> Is there a simple way to "shift" this data so my global plots look  
> correct? So far my results result in an "empty" line along the south  
> pole or I end up with an extra latitude which pcolor doesn't like.
>
> Thanks,
>
> Mike
>
>   

Mike:  From the pcolor docstring:

X and Y, if given, specify the (x,y) coordinates of the colored
quadrilaterals; the quadrilateral for C[i,j] has corners at
(X[i,j],Y[i,j]), (X[i,j+1],Y[i,j+1]), (X[i+1,j],Y[i+1,j]),
(X[i+1,j+1],Y[i+1,j+1]).  Ideally the dimensions of X and Y
should be one greater than those of C; if the dimensions are the
same, then the last row and column of C will be ignored.

So it may be easier to modify your data (by averaging adjacent values to 
they reflect the mid-point of each grid box) than to modify the vertices.

-Jeff

-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : [EMAIL PROTECTED]
325 BroadwayOffice : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] pcolor and

2008-03-11 Thread mbauer
Matplotlib users,

I've been using pcolor and pcolormesh to plot results from the NCEP  
Reanalysis. I've noticed that the plotted values are slightly offset.  
Googling around I see that matlab has this quality, which I assume  
matplotlib inherited.

 # If your georeferenced image is in lat/long coordinates (i.e.  
each data row is along a line of
   constant latitude, each column a line of equal longitude), ...  
you MUST remember to offset your
   coordinates by one-half of the pixel spacing. This is because  
of the different behaviors of
   p_color and image when given the same data.
1. image will center the drawn (i,j) pixel on the (i,j)th entry of  
the X/Y matrices.
2. p_color with shading flat will draw a panel between the (i,j), 
(i+1,j),(i+1,j+1),(i,j+1)
 coordinates of the X/Y matrices with a color corresponding to  
the data value at (i,j). Thus
 everything will appear shifted by one half a pixel spacing.

and
% Since the grid is rectangluar in lat/long (i.e. not
% really a projection at all, althouhg it is included in
% m_map under the name 'equidistant cyldindrical'), we
% don't want to use the 'image' technique. Instead...
% Create a grid, offsetting by half a grid point to account
% for the flat pcolor
[Plg,Plt]=meshgrid(Plon-0.25,Plat+0.25);

The data I'm using uses polar grids centered on +-90.0 which give a  
latitude array as such
[-90.  -87.5 -85.  -82.5 -80.  -77.5 -75.  -72.5 -70.  -67.5 -65.  -62.5
  -60.  -57.5 -55.  -52.5 -50.  -47.5 -45.  -42.5 -40.  -37.5 -35.   
-32.5
  -30.  -27.5 -25.  -22.5 -20.  -17.5 -15.  -12.5 -10.   -7.5  -5.
-2.5
0.2.5   5.7.5  10.   12.5  15.   17.5  20.   22.5  25.
27.5
   30.   32.5  35.   37.5  40.   42.5  45.   47.5  50.   52.5  55.
57.5
   60.   62.5  65.   67.5  70.   72.5  75.   77.5  80.   82.5  85.
87.5
   90. ]

Is there a simple way to "shift" this data so my global plots look  
correct? So far my results result in an "empty" line along the south  
pole or I end up with an extra latitude which pcolor doesn't like.

Thanks,

Mike

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap, Mercator Projection and pcolor

2008-03-11 Thread Rich Fought

> Rich:  What are X and Y set to?  They should be the map projection 
> coorindates of the grid.  If they are latitudes and longitudes, this 
> will work for 'cyl' but not 'merc'.  For 'merc', you must convert the 
> lats and lons to x and y using
>
> x, y = mp(lon, lat)
>
> -Jeff
>

Thanks Jeff, that did the trick ... I am working with lats/longs and I 
assumed that the conversion would be automatic for some reason.

Rich

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap, Mercator Projection and pcolor

2008-03-11 Thread Jeff Whitaker
Rich Fought wrote:
> Hi,
>
> I've successfully plotted gridded data on a basemap "cyl" projection 
> using pcolor:
>
>  mp = Basemap(projection="cyl", resolution="l", llcrnrlon=0.0, 
> urcrnrlon=30.0, llcrnrlat=-5.0, urcrnrlat=5.0)
>  pc = mp.pcolor(X, Y, zvalsm, cmap=cm.jet)
>
> However, if I simply I change the projection type to merc, adding 
> appropriate lat_ts, I get the projection but the pcolor fails to plot on 
> it:
>
>  mp = Basemap(projection="merc", lat_ts=0.0, resolution="l", 
> llcrnrlon=0.0, urcrnrlon=30.0, llcrnrlat=-5.0, urcrnrlat=5.0)'
>  pc = mp.pcolor(X, Y, zvalsm, cmap=cm.jet)
>
> Any ideas? I am using matplotlib 0.91.2 and basemap 0.9.9 on CentOS 4.0 
> with Python 2.3.
>
> Thanks,
> Rich
>
>   
Rich:  What are X and Y set to?  They should be the map projection coorindates 
of the grid.  If they are latitudes and longitudes, this will work for 'cyl' 
but not 'merc'.  For 'merc', you must convert the lats and lons to x and y using

x, y = mp(lon, lat)

-Jeff

-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : [EMAIL PROTECTED]
325 BroadwayOffice : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] contour question

2008-03-11 Thread Michael Droettboom
.get_paths() returns a list of Path objects.  (See path.py).  For each 
Path object, you can get an Nx2 array of vertices from its "vertices" 
member.  You can also use the "iter_segments" method to iterate through 
each of its vertices, but that's primarily only useful when there may be 
bezier curves in the path, which there won't be in the case of contours.

Missing docstrings is definitely a problem that will need to be worked on.

Cheers,
Mike

[EMAIL PROTECTED] wrote:
>   Hello,
>
> I'm using a svn version of matplotlib and the API changed for contour. I want 
> to have the coordinate of the contour. Before Eric Firing (I think) gave a 
> solution to do it:
>
> val = contour(xRange,yRange,delchi2,[1])
> t = asarray(val.collections[0].get_verts())
>
> but now get_verts doesn't exist anymore.
>
> I tried to do:
>
> cs = contour(a)
> path = cs.collections[0].get_paths()
>
> but I don't know how to use it. Basically I think that I have the contour 
> coordinate but I don't know how to recuperate them. I need it to export them 
> in a data file so it's the reason I want to recuperate them.
>
> Thank you for any help
>
> N.
>
> ps: It's a little bit difficult to access to the help for a method now some, 
> perhaps most, of them are missing a docstring. So it's difficult to 
> understand what it is the meaning of each of them.
>
> example:
>
> col.get_paths?
> Type:   instancemethod
> Base Class: 
> String Form: >
> Namespace:  Interactive
> File:   /usr/lib/python2.5/site-packages/matplotlib/collections.py
> Definition: col.get_paths(self)
> Docstring:
> 
>
>
>
>
>
> -
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>   

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Basemap, Mercator Projection and pcolor

2008-03-11 Thread Rich Fought
Hi,

I've successfully plotted gridded data on a basemap "cyl" projection 
using pcolor:

 mp = Basemap(projection="cyl", resolution="l", llcrnrlon=0.0, 
urcrnrlon=30.0, llcrnrlat=-5.0, urcrnrlat=5.0)
 pc = mp.pcolor(X, Y, zvalsm, cmap=cm.jet)

However, if I simply I change the projection type to merc, adding 
appropriate lat_ts, I get the projection but the pcolor fails to plot on 
it:

 mp = Basemap(projection="merc", lat_ts=0.0, resolution="l", 
llcrnrlon=0.0, urcrnrlon=30.0, llcrnrlat=-5.0, urcrnrlat=5.0)'
 pc = mp.pcolor(X, Y, zvalsm, cmap=cm.jet)

Any ideas? I am using matplotlib 0.91.2 and basemap 0.9.9 on CentOS 4.0 
with Python 2.3.

Thanks,
Rich

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] contour question

2008-03-11 Thread humufr
Hello,

I'm using a svn version of matplotlib and the API changed for contour. I want 
to have the coordinate of the contour. Before Eric Firing (I think) gave a 
solution to do it:

val = contour(xRange,yRange,delchi2,[1])
t = asarray(val.collections[0].get_verts())

but now get_verts doesn't exist anymore.

I tried to do:

cs = contour(a)
path = cs.collections[0].get_paths()

but I don't know how to use it. Basically I think that I have the contour 
coordinate but I don't know how to recuperate them. I need it to export them 
in a data file so it's the reason I want to recuperate them.

Thank you for any help

N.

ps: It's a little bit difficult to access to the help for a method now some, 
perhaps most, of them are missing a docstring. So it's difficult to 
understand what it is the meaning of each of them.

example:

col.get_paths?
Type:   instancemethod
Base Class: 
String Form:>
Namespace:  Interactive
File:   /usr/lib/python2.5/site-packages/matplotlib/collections.py
Definition: col.get_paths(self)
Docstring:






-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [newbie] "live" plots of multiple lines

2008-03-11 Thread Chris Withers
Ryan May wrote:
> 
> Right, the show() command starts the GUI's mainloop, which blocks 
> execution of the script until you close the figure.  What you probably 
> want is something like the dynamic_demo.py example.

...which barfes for me:

Traceback (most recent call last):
   File "dynamic_demo.py", line 3, in 
 import gobject
ImportError: No module named gobject

What does that mean?

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] colorbar problem

2008-03-11 Thread humufr
Le Sunday 09 March 2008 14:32:05 Eric Firing, vous avez écrit :
> [EMAIL PROTECTED] wrote:
> > Hello,
> >
> > I have some stupid questions about how to use colorbar.
> >
> > 1) I would like to be able to put the colorbar where I went: top, bottom,
> > left, right. For what I see I can do only a vertical left and horizontal
> > bottom ones (with a simple use of the function).
> > I know that it's possible to do a colorbar only but it's difficult to
> > place them a little bit automatically and that bring my second question.
>
> This looks like a feature request: instead of specifying "horizontal" or
> "vertical", be able to specify "top", "bottom", "left", or "right".
> This is fairly easy in principle, but there are some wrinkles such that
> I am not sure it would be satisfactory in practice--some custom
> adjustments might usually be needed depending on whether the main axes
> have a title (in the case of "top") or an xlabel (in the case of
> "left").  You may be better off simply figuring out what main and
> colorbar axes positions work best for your particular case and then
> making those axes explicitly.

I agree it's more feature request. I'll look on how to implement your 
suggestion. 

> > 2) I would like that the colorbar with exactly the same size than the
> > image I plot with pcolor. It's working when I'm not using the
> > aspect='equal' in the subplot but not with this option. Naturally I want
> > to not change the aspect of my image and so it's a big problem for me.
> > The only solution I found is to manipulate the colorbar with the shrink
> > valu but it's a little bit painfull especially the value change for each
> > pcolor image (they doesn't have always the same size).
>
> This is a common request, and a reasonable one, but unfortunately it is
> not straightforward to implement automatically given mpl's internal
> structure.  Again, however, you get the desired result quite easily by
> creating your own axes explicitly.

This is what I was afraid... So I have a stupid question but how to do this, 
create the axes at the same place than the pcolor image?

I can see how I can recuperate the axes coordinates but I don't know how to 
use them:

im = pylab.pcolor(a)
ax = im.get_axes()
cs = pylab.colorbar()

but after I'm a little bit lost...

> > 3) I would like to give a label to the colorbar (ie if the colorbar is at
> > the bottom a label under the colorbar etc). To tell people what means the
> > colors but I didn't find anyway to do it. xlabel work for the pcolor
> > object (as expected) and there are no colorbar.xlabel function.
>
> Use the set_label() method.
> ...
> cbar = fig1.colorbar(im,orientation='horizontal')
> cbar.set_label('label')
> ...

Great thanks it's working perfectly.

> Eric

Thank you for your help,

N.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [newbie] "live" plots of multiple lines

2008-03-11 Thread Chris Withers
Alan G Isaac wrote:
> On Tue, 11 Mar 2008, Chris Withers apparently wrote:
>> the first time I call show()
> 
> http://matplotlib.sourceforge.net/faq.html#SHOW

Okay, that tells me that I prettymuch don't want to be using show(), but 
I don't think I want interactive mode either...

What I'm trying to do is run a script and plot-and-show as I go.
The script reads the data to be plotted, but each set of points takes up 
to 20 minutes to generate, so I want to see the points appear on the 
graph as they arrive.

Is this possible? If so, how?

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [newbie] "live" plots of multiple lines

2008-03-11 Thread Alan G Isaac
On Tue, 11 Mar 2008, Chris Withers apparently wrote:
> the first time I call show()

http://matplotlib.sourceforge.net/faq.html#SHOW

hth,
Alan Isaac




-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [newbie] "live" plots of multiple lines

2008-03-11 Thread Chris Withers
Matthias Michler wrote:
> plot([x1], [y1], "bo", [x2], [y2], "r+")

This didn't work :-S

- the first time I call show(), execution never comes back to my script 
so the code never gets to plot any further points

- if I put the "show" after the plotting loop (which means I don't get 
the "live plotting" I'm after) then there are no lines between the 
points (well, the points don't show at all, but I'm guessing it's 
because there's no lines between the points)

- looking at the example, I'm left wondering how to pass keyword 
parameters such as "label" or use other methods such as plot_date

Any help greatfully received!

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Major Issue with 0.91.2 and Python-2.5

2008-03-11 Thread Michael Droettboom
I suspect there is an .afm font file on your new system that is untested 
with matplotlib and exhibiting something "new".

I would first try to track down which font file it is, and then send it 
to me off list and I'll have a look at what might be tripping up matplotlib.

Cheers,
Mike

Rich Shepard wrote:
>I upgraded my notebook to Slackware-12.0 (which includes python-2.5) and
> discovered that the application I'm developing no longer ran. Turns out that
> matplotlib went missing during the upgrade.
>
>So, I just built matplotlib-0.91.2 using the same matplotlib.Slackbuild
> script I used on my workstation/server, but this time it failed. The font
> manager seems to be the issue; the error message repeatedly is: "Found an
> unknown keyword in AFM header (was Underline)". Specifically, the error is
> in File "/usr/lib/Python2.5/site-packages/matplotlib/afm.py", line 166, in
> _parse_char_metrics
>   name=vals[2].split()[1]
> IndexError: List index out of range
>
>Is this unique to me? What do I do to fix the problem?
>
> TIA,
>
> Rich
>
>   

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Unable to Plot Date Axis Due To "TypeError: a float is required"

2008-03-11 Thread Chris Spencer
I'm getting a nonsensical error when attempting to make a simple plot
with a date axis. Googling shows this similar errors, but none with a
date axis. What could be causing this?

>>> import datetime
>>> from pylab import figure, show
>>> fig = figure()
>>> ax = fig.add_subplot(111)
>>> dates = [datetime.date(2008, 1, 30),datetime.date(2008, 1, 31)]
>>> values = [10.25, 10.0]
>>> ax.plot_date(dates, values)#, '-')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line
2585, in plot_date
ret = self.plot(x, y, fmt, **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 2535, in plot
for line in self._get_lines(*args, **kwargs):
  File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line
428, in _grab_next_args
for seg in self._plot_3_args(remaining, **kwargs):
  File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line
404, in _plot_3_args
func(x[:,j], y[:,j])
  File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line
385, in makeline
axes=self.axes,
  File "/usr/lib/python2.5/site-packages/matplotlib/lines.py", line
226, in __init__
self.set_data(xdata, ydata)
  File "/usr/lib/python2.5/site-packages/matplotlib/lines.py", line
315, in set_data
self.recache()
  File "/usr/lib/python2.5/site-packages/matplotlib/lines.py", line
320, in recache
x = ma.asarray(self.convert_xunits(self._xorig), Float)
  File "/usr/lib/python2.5/site-packages/numpy/core/ma.py", line 2122,
in asarray
return array(data, dtype=dtype, copy=0)
  File "/usr/lib/python2.5/site-packages/numpy/core/ma.py", line 573,
in __init__
self._data = c.astype(tc)
TypeError: a float is required

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] wx backend scaling problem

2008-03-11 Thread Gary Ruben
Hi Michael,

Michael Droettboom wrote:
> Well, that was a good puzzle!

Glad I got your neurons firing.

> This seems like a safe fix to me, but anyone who currently extends the 
> Wx Frame (meaning the whole window etc.) and is unknowingly compensating 
> for this effect may have problems after my change.

Many thanks for looking at this. I applied your fix and it works for me.

Gary R.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users