Thierry,

You need either scipy or rpy2 (and R) to do this. I've attached some code 
below. Please keep in mind that I've written for the general case of having a 
censored data set, therefore I rely on masked arrays from numpy.ma and 
scipy.stats.mstats -- but I have apply the mask midway through the process, 
which is different than the numpy's standard operating procedure. Let me know 
if any of this isn't clear.

I also have code that generates a quick comparison of the results from 
scipy.stats.mstats and ryp2+R, if you're interested.

HTH,
-paul

# code...
import matplotlib.pyplot as pl
import scipy.stats as st
import numpy as np

def censoredProbPlot(data, mask):
    ppos = st.mstats.plotting_positions(data)
    qntl = st.distributions.norm.ppf(ppos)
    
    qntlMask = np.ma.MaskedArray(qntl, mask=mask)
    dataMask = np.ma.MaskedArray(data, mask=mask)
    
    fit = st.mstats.linregress(dataMask, qntlMask)
    mu = -fit[1]
    sigma = fit[0]
    d_ = np.linspace(np.min(data),np.max(data))
    q_ = sigma * d_ - mu
    
    maskedProbPlot = {"mskData" : dataMask,
                      "mskQntl" : qntlMask,
                      "unmskData" : data,
                      "unmskQntl" : qntl,
                      "bestFitD" : d_,
                      "bestFitQ" : q_,
                      "mu" : mu,
                      "sigma" : sigma}
    return maskedProbPlot

if 1:
    #~~ you need to put your data here:
    #data = np.array([])
    #mask = np.array([],dtype=bool)

    mpp = censoredProbPlot(data, mask)

    fig = pl.figure()
    ax1 = fig.add_subplot(111)
    ax1.plot(mpp['mskQntl'], mpp['mskData'], 'ko', ms=6, label='Detected 
Samples')
    ax1.plot(mpp['unmskQntl'], mpp['unmskData'], 'r.', ms=6, label='Raw 
Samples')
    ax1.plot(mpp['bestFitQ'], mpp['bestFitD'], 'b-', lw=2)
    fig.savefig('example_censoredProbPlot.png')


> -----Original Message-----
> From: MONTAGU Thierry [mailto:thierry.mont...@cea.fr]
> Sent: Friday, May 21, 2010 6:37 AM
> To: matplotlib-users@lists.sourceforge.net
> Subject: [Matplotlib-users] qqplot
> 
> hi all
> 
> has anyone ever tried to make a quantile-quantile plot with pylab?
> is there any build in function named say "qqplot" available ?
> 
> thanks
> Thierry
> 
> -------------------------------------------------------------------------
> -----
> 
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------

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

Reply via email to