 # 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

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

ppos = st.mstats.plotting_positions(data)
qntl = st.distributions.norm.ppf(ppos)

mu = -fit
sigma = fit
d_ = np.linspace(np.min(data),np.max(data))
q_ = sigma * d_ - mu

"unmskData" : data,
"unmskQntl" : qntl,
"bestFitD" : d_,
"bestFitQ" : q_,
"mu" : mu,
"sigma" : sigma}

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

fig = pl.figure()
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.montagu@…3117…]
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

From: MONTAGU Thierry [mailto:thierry.montagu@…3117…]
Sent: Friday, May 21, 2010 09:37

has anyone ever tried to make a quantile-quantile plot with pylab?
is there any build in function named say "qqplot" available ?

For a plot comparing samples to a theoretical distribution (and if you don't
need masking as in Paul's example), you might be able to use
scipy.stats.probplot, as follows:

import matplotlib.pyplot as plt
import scipy.stats as st

values = st.norm.rvs(size=(100,)) # example data
fig = plt.figure() # set up plot