How to make Q-Q plots
What are Q-Q plots?
A Q-Q plot is used to compare two distributions against each other. Q-Q plots are especially helpful for testing your assumptions about a given distribution because you can use a Q-Q plot to examine the differences between any given distribution and a uniform distribution (effectively representing a null hypothesis). P-values can be obtained from any number of statistical tests including the t-test, f-test, rank-sum test, etc. In a standard Q-Q plot, the x-axis represents the theoretical p-values given the null hypothesis, (uniformly distributed) and the y-axis represents observed p-values, i.e. the ones we obtain from testing.
Below is an example in Python.
import numpy as np
import matplotlib.pyplot as plt
n = 5000 # number of tests
# create dummy 'observed' p values
obs_p = np.random.rand(1,n)[0]
obs_p = -np.log10(np.sort(obs_p))
th_p = np.arange(1/float(n),1+(1/float(n)),1/float(n))
th_p = -np.log10(th_p)
fig, ax = plt.subplots(ncols=1)
ax.scatter(th_p,obs_p)
x = np.linspace(*ax.get_xlim())
ax.plot(x, x)
plt.show()