-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContinuous_parameter.py
50 lines (40 loc) · 1.24 KB
/
Continuous_parameter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('pdf', 'svg') #Save plots in PDF (vectorized format)
import matplotlib
#Use of LaTeX in labels
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
#Function to plot
def f(x, alpha):
return np.exp(- alpha * x)
#x range
x = np.linspace(0, 10, 100)
#alpha range
alpha_min = .5
alpha_max = 5
alpha_number = 20
alpha = np.linspace(alpha_min, alpha_max, alpha_number)
#Initialize plot
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
#Initialize min and max value for alpha
norm = matplotlib.colors.Normalize(vmin = alpha_min, vmax = alpha_max)
#Choose a colormap
c_m = matplotlib.cm.viridis
#Initialize the colorbar
s_m = matplotlib.cm.ScalarMappable(cmap = c_m, norm = norm)
s_m.set_array([])
cb = plt.colorbar(s_m, shrink = 0.8)
#Colorbar label with position
cb.set_label("$\\alpha$", y = 1.12, rotation = 0, labelpad = -16, fontsize = 15)
#Loop on alpha values
#For each i, plot f(x) for a value of alpha
for i in range(alpha_number):
y = f(x, alpha[i])
ax.plot(x, y, color = s_m.to_rgba(alpha[i]))
#Labels
ax.set_xlabel("$x$", fontsize = 15)
ax.set_ylabel("$y = \\exp (-\\alpha x)$", fontsize = 15)
plt.show()