Convert data into rectangular grid
Hi, Suppose I have a set of x,y,c data (something useful for matplotlib.pyplot.plot() ). Generally, this data is not rectangular at all. Does there exist a numpy function (or set of functions) which will take this data and construct the smallest two-dimensional arrays X,Y,C ( suitable for matplotlib.pyplot.contour() ). Essentially, I want to pass in the data and a grid step size in the x- and y-directions. The function would average the c-values for all points which land in any particular square. Optionally, I'd like to be able to specify a value to use when there are no points in x,y which are in the square. Hope this makes sense.
On Mon, Sep 28, 2009 at 7:19 PM, jah
Hi,
Suppose I have a set of x,y,c data (something useful for matplotlib.pyplot.plot() ). Generally, this data is not rectangular at all. Does there exist a numpy function (or set of functions) which will take this data and construct the smallest two-dimensional arrays X,Y,C ( suitable for matplotlib.pyplot.contour() ).
Essentially, I want to pass in the data and a grid step size in the x- and y-directions. The function would average the c-values for all points which land in any particular square. Optionally, I'd like to be able to specify a value to use when there are no points in x,y which are in the square.
Hope this makes sense.
If I understand correctly numpy.histogram2d(x, y, ..., weights=c) might do what you want. There was a recent thread on its usage. Josef
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Mon, Sep 28, 2009 at 4:48 PM,
On Mon, Sep 28, 2009 at 7:19 PM, jah
wrote: Hi,
Suppose I have a set of x,y,c data (something useful for matplotlib.pyplot.plot() ). Generally, this data is not rectangular at all. Does there exist a numpy function (or set of functions) which will take this data and construct the smallest two-dimensional arrays X,Y,C ( suitable for matplotlib.pyplot.contour() ).
Essentially, I want to pass in the data and a grid step size in the x- and y-directions. The function would average the c-values for all points which land in any particular square. Optionally, I'd like to be able to specify a value to use when there are no points in x,y which are in the square.
Hope this makes sense.
If I understand correctly numpy.histogram2d(x, y, ..., weights=c) might do what you want.
There was a recent thread on its usage.
It is very close, but it normed=True, will first normalize the weights (undesirably) and then it will normalize the normalized weights by dividing by the cell area. Instead, what I want is the cell value to be the average off all the points that were placed in the cell. This seems like a common use case, so I'm guessing this functionality is present already. So if 3 points with weights [10,20,30] were placed in cell (i,j), then the cell should have value 20 (the arithmetic mean of the points placed in the cell). Here is the desired use case: I have a set of x,y,c values that I could pass into matplotlib's scatter() or hexbin(). I'd like to take this same set of points and transform them so that I can pass them into matplotlib's contour() function. Perhaps matplotlib has a function which does this.
On Mon, Sep 28, 2009 at 19:45, jah
Here is the desired use case: I have a set of x,y,c values that I could pass into matplotlib's scatter() or hexbin(). I'd like to take this same set of points and transform them so that I can pass them into matplotlib's contour() function. Perhaps matplotlib has a function which does this.
http://matplotlib.sourceforge.net/api/mlab_api.html#matplotlib.mlab.griddata -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
On Mon, Sep 28, 2009 at 8:45 PM, jah
On Mon, Sep 28, 2009 at 4:48 PM,
wrote: On Mon, Sep 28, 2009 at 7:19 PM, jah
wrote: Hi,
Suppose I have a set of x,y,c data (something useful for matplotlib.pyplot.plot() ). Generally, this data is not rectangular at all. Does there exist a numpy function (or set of functions) which will take this data and construct the smallest two-dimensional arrays X,Y,C ( suitable for matplotlib.pyplot.contour() ).
Essentially, I want to pass in the data and a grid step size in the x- and y-directions. The function would average the c-values for all points which land in any particular square. Optionally, I'd like to be able to specify a value to use when there are no points in x,y which are in the square.
Hope this makes sense.
If I understand correctly numpy.histogram2d(x, y, ..., weights=c) might do what you want.
There was a recent thread on its usage.
It is very close, but it normed=True, will first normalize the weights (undesirably) and then it will normalize the normalized weights by dividing by the cell area. Instead, what I want is the cell value to be the average off all the points that were placed in the cell. This seems like a common use case, so I'm guessing this functionality is present already. So if 3 points with weights [10,20,30] were placed in cell (i,j), then the cell should have value 20 (the arithmetic mean of the points placed in the cell).
s = histogram2d(x,y,weights=c) # Not normalized, so you get the sum of
Would this work for you ? the weights
n = histogram2d(x,y) # Now you have the number of elements in each bin mean = s/n
David
Here is the desired use case: I have a set of x,y,c values that I could pass into matplotlib's scatter() or hexbin(). I'd like to take this same set of points and transform them so that I can pass them into matplotlib's contour() function. Perhaps matplotlib has a function which does this.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On Wed, Sep 30, 2009 at 8:57 AM, denis bzowy
jah
writes: Hi,Suppose I have a set of x,y,c data ... matplotlib.pyplot.contour() ).
JAH, is griddata() working and fast enough for you ? How many points are you contouring ?
Thanks all. Robert, griddata is exactly what I was looking for. David, I think that should work too. And Denis, griddata is sufficiently fast that I am not complaining---contouring about 1e6 or 1e7 points typically.
Thanks all. Robert, griddata is exactly what I was looking for. David, I
jah
Fyinfo, take a look at http://yt.enzotools.org "YT is an analysis and visualization system written in Python, designed for use with Adaptive Mesh Refinement codes ..." I haven't used it, but the doc and pictures are terrific, top 2 % or better
participants (5)
-
David Huard
-
denis bzowy
-
jah
-
josef.pktd@gmail.com
-
Robert Kern