ex-1: add the possibility of plotting a Cauchy PDF and create the plot
This commit is contained in:
parent
6c1eab897f
commit
d61498cdaa
@ -6,12 +6,13 @@ import argparse
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
# -i → agrs.show → open plot in interactive mode
|
# -i → agrs.show → open plot in interactive mode
|
||||||
# -s → args.save → save plot
|
# -s → args.save → save plot
|
||||||
#
|
#
|
||||||
# -n → agrs.note → do the Landau plot with the notes
|
# -n → agrs.note → do the Landau plot with the notes
|
||||||
# -b → args.both → do the Landau-Moyal plot
|
# -b → args.both → do the Landau-Moyal plot
|
||||||
# -m → args.area → do the Landau median plot
|
# -m → args.area → do the Landau median plot
|
||||||
|
# -c → args.cauchy → do the Cauchy PDF plot
|
||||||
|
|
||||||
|
|
||||||
def moyal(x, μ, σ):
|
def moyal(x, μ, σ):
|
||||||
@ -19,20 +20,24 @@ def moyal(x, μ, σ):
|
|||||||
return N * np.exp(- 0.5 * ((x - μ)/σ + np.exp(- (x - μ)/σ)))
|
return N * np.exp(- 0.5 * ((x - μ)/σ + np.exp(- (x - μ)/σ)))
|
||||||
|
|
||||||
|
|
||||||
|
def cauchy(x):
|
||||||
|
return 1/(np.pi*(1 + x**2))
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
# prepare figure
|
# prepare figure
|
||||||
if args.show:
|
if args.show:
|
||||||
plt.figure()
|
plt.figure()
|
||||||
|
|
||||||
elif args.save:
|
elif args.save:
|
||||||
plt.rcParams['font.size'] = 8
|
plt.rcParams['font.size'] = 8
|
||||||
if (args.both or args.area):
|
if (args.both or args.area):
|
||||||
plt.figure(figsize=(3, 2))
|
plt.figure(figsize=(3, 2))
|
||||||
elif args.note:
|
elif args.note:
|
||||||
plt.figure(figsize=(5, 3))
|
plt.figure(figsize=(5, 3))
|
||||||
|
elif args.cauchy:
|
||||||
|
plt.figure(figsize=(3, 2))
|
||||||
|
|
||||||
if args.note:
|
if args.note:
|
||||||
|
|
||||||
# useful coordinates
|
# useful coordinates
|
||||||
y_min = -0.0086 # y min axes
|
y_min = -0.0086 # y min axes
|
||||||
y_max = 0.1895 # y max axes
|
y_max = 0.1895 # y max axes
|
||||||
@ -85,6 +90,12 @@ def main(args):
|
|||||||
plt.plot(x, moyal(x, μ, σ), color='gray', label='Moyal')
|
plt.plot(x, moyal(x, μ, σ), color='gray', label='Moyal')
|
||||||
plt.legend()
|
plt.legend()
|
||||||
|
|
||||||
|
# do Cauchy plot
|
||||||
|
if args.cauchy:
|
||||||
|
x = np.arange(-10, 10, 0.01)
|
||||||
|
plt.plot(x, cauchy(x), color='gray', label='Cauchy')
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
# save figure
|
# save figure
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
if args.show:
|
if args.show:
|
||||||
@ -96,6 +107,8 @@ def main(args):
|
|||||||
plt.savefig('slides/images/both-pdf.pdf', transparent=True)
|
plt.savefig('slides/images/both-pdf.pdf', transparent=True)
|
||||||
if args.area:
|
if args.area:
|
||||||
plt.savefig('slides/images/median.pdf', transparent=True)
|
plt.savefig('slides/images/median.pdf', transparent=True)
|
||||||
|
if args.cauchy:
|
||||||
|
plt.savefig('slides/images/cauchy-pdf.pdf')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -116,5 +129,8 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('-a', '--area',
|
parser.add_argument('-a', '--area',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='do the area plot')
|
help='do the area plot')
|
||||||
|
parser.add_argument('-c', '--cauchy',
|
||||||
|
action='store_true', default=False,
|
||||||
|
help='do the cauchy plot')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
main(args)
|
main(args)
|
||||||
|
BIN
slides/images/cauchy-pdf.pdf
Normal file
BIN
slides/images/cauchy-pdf.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user