Re: [Matplotlib-users] Region within contour -- 2D array

2014-08-29 Thread Benjamin Root
slaps forehead...

Joe, you just won the duh! moment of the month award!

Cheers!
Ben Root



On Thu, Aug 28, 2014 at 10:18 PM, Joe Kington joferking...@gmail.com
wrote:

 Why not just use boolean indexing?

 E.g. to find the region that falls between 5 and 10, do (z =5)  (z =
 10):

 In [1]: import numpy as np

 In [2]: x, y = np.mgrid[-10:10, -10:10]

 In [3]: z = np.hypot(x, y)

 In [4]: result = (z = 5)  (z = 10)

 In [5]: result.astype(int)
 Out[5]:
 array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]])

 Cheers,
 -Joe



 On Thu, Aug 28, 2014 at 8:23 PM, Eric Firing efir...@hawaii.edu wrote:

 On 2014/08/28, 3:02 AM, Matthew Czesarski wrote:
  Hi Matplotlib Users!
 
 
 
  I have some 2-d arrays, which i am displaying  with implot, and deriving
  contours for with contour.  Easy -  I'm just pulling them out of
  collections[0].get_paths() .
 
  However what's not easy is that I would like to recover a 1-0 or
  True-False array of the array values (pixels) that fall within the
  contours. Some line crossing algorithm/floodfill could do it, but I
  guess that matplotlib's fill() or contourf() must do this under the hood
  anyway. I've looked into the output both functions, but I don't see
  anything obvious..
 
  Does anybody know if there's an a way to pull out a such an array from
  matplotlib?   Any pointers are appreciated!

 Make an array of (x, y) pairs from the X and Y you use in your call to
 contour, and then feed that array to the contains_points() method of
 your contour Path.  This will give you the desired Boolean array for any
 given Path; depending on what you want, you might need to combine arrays
 for more than one Path.

 To get closed paths, I think you will want to use contourf, not contour.

 Eric



 
  Cheers,
  Matt
 
 
 
 --
  Slashdot TV.
  Video for Nerds.  Stuff that matters.
  http://tv.slashdot.org/
 
 
 
  ___
  Matplotlib-users mailing list
  Matplotlib-users@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 



 --
 Slashdot TV.
 Video for Nerds.  Stuff that matters.
 http://tv.slashdot.org/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users




 --
 Slashdot TV.
 Video for Nerds.  Stuff that matters.
 http://tv.slashdot.org/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Region within contour -- 2D array

2014-08-28 Thread Matthew Czesarski
Hi Matplotlib Users!



I have some 2-d arrays, which i am displaying  with implot, and deriving
contours for with contour.  Easy -  I'm just pulling them out of
collections[0].get_paths() .

However what's not easy is that I would like to recover a 1-0 or True-False
array of the array values (pixels) that fall within the contours. Some line
crossing algorithm/floodfill could do it, but I guess that matplotlib's
fill() or contourf() must do this under the hood anyway. I've looked into
the output both functions, but I don't see anything obvious..

Does anybody know if there's an a way to pull out a such an array from
matplotlib?   Any pointers are appreciated!

Cheers,
Matt
--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Region within contour -- 2D array

2014-08-28 Thread Shantha Kumara
Hi All,

Thank you so much for your help, It really worked for me.


I need one more favor,


I have ploted the graph with 2 Y-axes

Here is the code

 lns1 = ax1.plot(x1, y1, 'r-o',label=LY1,markersize=4)
ax1 = self.set_ylim(ax1,y1,label=LY1)
lns2 = ax2.plot(x2, y2, 'b-o',label=LY2,markersize=4)

I want to set the grid to the second y-axes in the same graph.

Please help on the same.

See here the difference

(Embedded image moved to file: pic19302.gif)



SHANTHA KUMARA REVANASIDDAPPA
Python Developper
Operations  Production Control, A1 Telekom
IBM
M   +43-6642196132
@shantha.kumara.kadur.revanasidda...@ext.a1telekom.at--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Region within contour -- 2D array

2014-08-28 Thread Benjamin Root
That stuff is done in the deep underbelly of matplotlib and isn't exposed
to the user. It is done as part of the rendering process in AGG or
whichever other backend is performing the render. I have done something
very similar to what you are asking for my job, and while I can't share the
code, I can point out that GDAL has a very fast polygon rasterizer. I can
also point you to this link:
http://stackoverflow.com/questions/2220749/rasterizing-a-gdal-layer

I will also say that there are some subtle errors in that code, but it
should get you to where you need to go.

Cheers!
Ben Root



On Thu, Aug 28, 2014 at 9:02 AM, Matthew Czesarski 
matthew.czesar...@gmail.com wrote:

 Hi Matplotlib Users!



 I have some 2-d arrays, which i am displaying  with implot, and deriving
 contours for with contour.  Easy -  I'm just pulling them out of
 collections[0].get_paths() .

 However what's not easy is that I would like to recover a 1-0 or
 True-False array of the array values (pixels) that fall within the
 contours. Some line crossing algorithm/floodfill could do it, but I guess
 that matplotlib's fill() or contourf() must do this under the hood anyway.
 I've looked into the output both functions, but I don't see anything
 obvious..

 Does anybody know if there's an a way to pull out a such an array from
 matplotlib?   Any pointers are appreciated!

 Cheers,
 Matt


 --
 Slashdot TV.
 Video for Nerds.  Stuff that matters.
 http://tv.slashdot.org/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Region within contour -- 2D array

2014-08-28 Thread Eric Firing
On 2014/08/28, 3:02 AM, Matthew Czesarski wrote:
 Hi Matplotlib Users!



 I have some 2-d arrays, which i am displaying  with implot, and deriving
 contours for with contour.  Easy -  I'm just pulling them out of
 collections[0].get_paths() .

 However what's not easy is that I would like to recover a 1-0 or
 True-False array of the array values (pixels) that fall within the
 contours. Some line crossing algorithm/floodfill could do it, but I
 guess that matplotlib's fill() or contourf() must do this under the hood
 anyway. I've looked into the output both functions, but I don't see
 anything obvious..

 Does anybody know if there's an a way to pull out a such an array from
 matplotlib?   Any pointers are appreciated!

Make an array of (x, y) pairs from the X and Y you use in your call to 
contour, and then feed that array to the contains_points() method of 
your contour Path.  This will give you the desired Boolean array for any 
given Path; depending on what you want, you might need to combine arrays 
for more than one Path.

To get closed paths, I think you will want to use contourf, not contour.

Eric




 Cheers,
 Matt


 --
 Slashdot TV.
 Video for Nerds.  Stuff that matters.
 http://tv.slashdot.org/



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



--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Region within contour -- 2D array

2014-08-28 Thread Joe Kington
Why not just use boolean indexing?

E.g. to find the region that falls between 5 and 10, do (z =5)  (z =
10):

In [1]: import numpy as np

In [2]: x, y = np.mgrid[-10:10, -10:10]

In [3]: z = np.hypot(x, y)

In [4]: result = (z = 5)  (z = 10)

In [5]: result.astype(int)
Out[5]:
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,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 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]])

Cheers,
-Joe



On Thu, Aug 28, 2014 at 8:23 PM, Eric Firing efir...@hawaii.edu wrote:

 On 2014/08/28, 3:02 AM, Matthew Czesarski wrote:
  Hi Matplotlib Users!
 
 
 
  I have some 2-d arrays, which i am displaying  with implot, and deriving
  contours for with contour.  Easy -  I'm just pulling them out of
  collections[0].get_paths() .
 
  However what's not easy is that I would like to recover a 1-0 or
  True-False array of the array values (pixels) that fall within the
  contours. Some line crossing algorithm/floodfill could do it, but I
  guess that matplotlib's fill() or contourf() must do this under the hood
  anyway. I've looked into the output both functions, but I don't see
  anything obvious..
 
  Does anybody know if there's an a way to pull out a such an array from
  matplotlib?   Any pointers are appreciated!

 Make an array of (x, y) pairs from the X and Y you use in your call to
 contour, and then feed that array to the contains_points() method of
 your contour Path.  This will give you the desired Boolean array for any
 given Path; depending on what you want, you might need to combine arrays
 for more than one Path.

 To get closed paths, I think you will want to use contourf, not contour.

 Eric



 
  Cheers,
  Matt
 
 
 
 --
  Slashdot TV.
  Video for Nerds.  Stuff that matters.
  http://tv.slashdot.org/
 
 
 
  ___
  Matplotlib-users mailing list
  Matplotlib-users@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 



 --
 Slashdot TV.
 Video for Nerds.  Stuff that matters.
 http://tv.slashdot.org/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Region within contour -- 2D array

2014-08-28 Thread Sterling Smith
Joe and list,

This is off topic, but can you point me to good documentation on the use of '' 
as opposed to numpy.logical_and ?

Thanks,
Sterling

On Aug 28, 2014, at 7:18PM, Joe Kington wrote:

 Why not just use boolean indexing?  
 
 E.g. to find the region that falls between 5 and 10, do (z =5)  (z = 10):
 
 In [1]: import numpy as np
 
 In [2]: x, y = np.mgrid[-10:10, -10:10]
 
 In [3]: z = np.hypot(x, y)
 
 In [4]: result = (z = 5)  (z = 10)
 
 In [5]: result.astype(int)
 Out[5]: 
 array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]])
 
 Cheers,
 -Joe
 
 
 
 On Thu, Aug 28, 2014 at 8:23 PM, Eric Firing efir...@hawaii.edu wrote:
 On 2014/08/28, 3:02 AM, Matthew Czesarski wrote:
  Hi Matplotlib Users!
 
 
 
  I have some 2-d arrays, which i am displaying  with implot, and deriving
  contours for with contour.  Easy -  I'm just pulling them out of
  collections[0].get_paths() .
 
  However what's not easy is that I would like to recover a 1-0 or
  True-False array of the array values (pixels) that fall within the
  contours. Some line crossing algorithm/floodfill could do it, but I
  guess that matplotlib's fill() or contourf() must do this under the hood
  anyway. I've looked into the output both functions, but I don't see
  anything obvious..
 
  Does anybody know if there's an a way to pull out a such an array from
  matplotlib?   Any pointers are appreciated!
 
 Make an array of (x, y) pairs from the X and Y you use in your call to
 contour, and then feed that array to the contains_points() method of
 your contour Path.  This will give you the desired Boolean array for any
 given Path; depending on what you want, you might need to combine arrays
 for more than one Path.
 
 To get closed paths, I think you will want to use contourf, not contour.
 
 Eric
 
 
 
 
  Cheers,
  Matt
 
 
  --
  Slashdot TV.
  Video for Nerds.  Stuff that matters.
  http://tv.slashdot.org/
 
 
 
  ___
  Matplotlib-users mailing list
  Matplotlib-users@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
 
 
 --
 Slashdot TV.
 Video for Nerds.  Stuff that matters.
 http://tv.slashdot.org/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
 --
 Slashdot TV.  
 Video for Nerds.  Stuff that matters.
 http://tv.slashdot.org/___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users