Tanggal :September 22, 2020

py27. Cauchy Distribution in Python

Spread the love

The Cauchy Cumulative Distribution Function is:


We use this formula as well as scipy.stats.cauchy.cdf function in the plot, and the two lines are plotted with different linewidths.

# ex27.py
from __future__ import print_function, division
import matplotlib.pyplot as plt
from numpy import linspace, pi, arctan as atan
from scipy.stats import cauchy
N = 500
gamma = 2
x0 = 3
x = linspace(-5*gamma+x0,+5*gamma+x0,num = N)
y = 1/pi*atan((x-x0)/gamma) + 0.5
y1 = cauchy.cdf(x, loc = x0, scale = gamma)
title = 'Cauchy CDF, gamma = %.1f, and x0 = %.1f' % (gamma, x0)
plt.plot(x,y, 'k', lw = 10)
plt.plot(x,y1,'g', lw = 5)
plt.title(title)
plt.show()

Output:

Share

Leave a Reply

Your email address will not be published. Required fields are marked *