python-scipyHow do I create a QQ plot using Python and SciPy?
To create a QQ plot using Python and SciPy, you can use the probplot()
function from the scipy.stats
module. This function takes two arguments, the first being the data to be plotted, and the second being the distribution of the data. Here is an example code block:
import matplotlib.pyplot as plt
from scipy.stats import probplot
data = [1,2,3,4,5,6]
probplot(data, dist='norm', plot=plt)
plt.show()
This will produce a QQ plot that looks like this:
Code explanation
import matplotlib.pyplot as plt
imports thepyplot
module from thematplotlib
library, which is used to display the plot.from scipy.stats import probplot
imports theprobplot
function from thescipy.stats
module, which is used to create the QQ plot.data = [1,2,3,4,5,6]
creates a list of data points that will be plotted.probplot(data, dist='norm', plot=plt)
calls theprobplot()
function with the data points and the normal distribution as arguments.plt.show()
displays the plot.
For more information, see this page from the SciPy documentation.
More of Python Scipy
- How do I create a 2D array of zeros using Python and NumPy?
- How can I use Python and SciPy to find the zeros of a function?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How can I use Python Scipy to zoom in on an image?
- How do I use Python Scipy to perform a Z test?
- How can I use the x.shape function in Python Numpy?
- How can I use Python and Numpy to parse XML data?
- How do I use scipy's griddata function in Python?
- How to use Python, XML-RPC, and NumPy together?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
See more codes...