Administrator

Hello,
I am performing a curve fit and also showing a distribution histogram envelope in my plot. In order to help the reader to evaluate the result I would like to draw certain boundaries (vertical and horizontal lines). While I am aware on how to draw such lines with matplotlib, I would like to know whether there are some functions in scipy or matplotlib which help me to retrieve the coordinates a) at which two curves intersect b) at which a distribution reaches a certain value? Example: How do I get the yaxis value which is reached by the green curve in http://matplotlib.sourceforge.net/_images/histogram_demo_extended_021.png at a xaxis value of in 175? I could proably use a solver from numpy like http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html#numpy.linalg.solve but if I plot a distribution, the equation of the envelove is unknown at the first place. I'd appreciate your help or pointers to examples. Thanks a lot in advance, Timmie _______________________________________________ SciPyUser mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipyuser 
Administrator

Hello,
my mail seems to have been too theoretical. Below is some example code. How can I calculate the intersection point (coordinates) between 'distribution_curve' and 'limit_line'? Which functions could help me here? Thanks in advance for any help / pointers. Best regards, Timmie ##### EXAMPLE CODE ####### #!/usr/bin/env python import pylab as P import numpy as np # first create a single histogram # mu, sigma = 200, 25 x = mu + sigma*P.randn(10000) n, bins = np.histogram(x) # add a line showing the expected distribution y = P.normpdf( bins, mu, sigma).cumsum() y /= y[1] # the curve for the plot shwoing the distribution distribution_curve = P.plot(bins, y, 'k', linewidth=1.5) # the limit of which the intersection # point (x / y) with distribution_curve is desired limit_line = P.axvline(x.mean()) P.show() _______________________________________________ SciPyUser mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipyuser 
On Wed, Mar 3, 2010 at 16:13, Tim Michelsen <[hidden email]> wrote:
> Hello, > my mail seems to have been too theoretical. > > Below is some example code. > > How can I calculate the intersection point (coordinates) between > 'distribution_curve' and 'limit_line'? > > Which functions could help me here? For finding where a monotonically increasing sequence crosses a particular value, use np.searchsorted() with the Y coordinate array and the value. This gives you the index into the Y array. Use that index on the X values to find the X value where it crosses. Depending on how you are interpreting those points, you may want that value, or the next one, or some weighted average of the two. For two sequences that cross, again it depends a little on the sequences themselves and on how you interpret the sequences. Are they step functions, or would you draw line segments from point to point? Are they monotonic? Do they have the same X values? Do they have the same set of Y values? etc. You could cobble something together where you evaluate "h(x) = f(x)  g(x)" (where f(x) and g(x) use interp1d on the original datasets) on the set of X points that is the union of the two sequences of X points from the two datasets. Then search for zero crossings (there may be more than one).  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 _______________________________________________ SciPyUser mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipyuser 
Free forum by Nabble  Edit this page 