the-last-thing/code/plots/laplace-graph.py

39 lines
879 B
Python
Raw Permalink Normal View History

2021-08-04 00:02:28 +02:00
#!/usr/bin/env python3
import sys
sys.path.insert(1, 'code/lib')
import lmdk_lib
import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import laplace
# Initialize plot
lmdk_lib.plot_init()
# The x axis
2022-01-07 06:17:37 +01:00
x = np.arange(-3, 3.1, .1)
plt.xlabel('Noise')
2021-08-04 00:02:28 +02:00
# Set y axis label
plt.ylabel('Likelihood')
# Draw the first laplace distribution
plt.plot(x,
2022-01-07 06:17:37 +01:00
laplace.pdf(x, loc=0, scale=1/1),
label='Lap(0, 1)',
linewidth=lmdk_lib.line_width*2)
plt.plot(x,
laplace.pdf(x, loc=0, scale=1/.5),
label='Lap(0, 2)',
linewidth=lmdk_lib.line_width*2)
plt.plot(x,
laplace.pdf(x, loc=0, scale=1/.25),
label='Lap(0, 4)',
linewidth=lmdk_lib.line_width*2)
2021-08-04 00:02:28 +02:00
# Configure the plot
2022-01-07 06:17:37 +01:00
plt.axis([-3, 3, 0.0, 0.6]) # Set plot box.
2021-08-04 00:02:28 +02:00
# Plot legend
lmdk_lib.plot_legend()
# Show the plot in a new window
plt.show()