ex-1: add the possibility of plotting a Cauchy PDF and create the plot
This commit is contained in:
parent
6c1eab897f
commit
d61498cdaa
@ -12,6 +12,7 @@ import sys
|
||||
# -n → agrs.note → do the Landau plot with the notes
|
||||
# -b → args.both → do the Landau-Moyal plot
|
||||
# -m → args.area → do the Landau median plot
|
||||
# -c → args.cauchy → do the Cauchy PDF plot
|
||||
|
||||
|
||||
def moyal(x, μ, σ):
|
||||
@ -19,20 +20,24 @@ def moyal(x, μ, σ):
|
||||
return N * np.exp(- 0.5 * ((x - μ)/σ + np.exp(- (x - μ)/σ)))
|
||||
|
||||
|
||||
def cauchy(x):
|
||||
return 1/(np.pi*(1 + x**2))
|
||||
|
||||
|
||||
def main(args):
|
||||
# prepare figure
|
||||
if args.show:
|
||||
plt.figure()
|
||||
|
||||
elif args.save:
|
||||
plt.rcParams['font.size'] = 8
|
||||
if (args.both or args.area):
|
||||
plt.figure(figsize=(3, 2))
|
||||
elif args.note:
|
||||
plt.figure(figsize=(5, 3))
|
||||
elif args.cauchy:
|
||||
plt.figure(figsize=(3, 2))
|
||||
|
||||
if args.note:
|
||||
|
||||
# useful coordinates
|
||||
y_min = -0.0086 # y min 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.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
|
||||
plt.tight_layout()
|
||||
if args.show:
|
||||
@ -96,6 +107,8 @@ def main(args):
|
||||
plt.savefig('slides/images/both-pdf.pdf', transparent=True)
|
||||
if args.area:
|
||||
plt.savefig('slides/images/median.pdf', transparent=True)
|
||||
if args.cauchy:
|
||||
plt.savefig('slides/images/cauchy-pdf.pdf')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@ -116,5 +129,8 @@ if __name__ == '__main__':
|
||||
parser.add_argument('-a', '--area',
|
||||
action='store_true', default=False,
|
||||
help='do the area plot')
|
||||
parser.add_argument('-c', '--cauchy',
|
||||
action='store_true', default=False,
|
||||
help='do the cauchy plot')
|
||||
args = parser.parse_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