forked from TikhonJelvis/RL-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_funcs.py
52 lines (48 loc) · 1.2 KB
/
plot_funcs.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
51
52
import matplotlib.pyplot as plt
import numpy as np
def plot_list_of_curves(
list_of_x_vals,
list_of_y_vals,
list_of_colors,
list_of_curve_labels,
x_label=None,
y_label=None,
title=None
):
plt.figure(figsize=(11, 7))
for i, x_vals in enumerate(list_of_x_vals):
plt.plot(
x_vals,
list_of_y_vals[i],
list_of_colors[i],
label=list_of_curve_labels[i]
)
plt.axis((
min(map(min, list_of_x_vals)),
max(map(max, list_of_x_vals)),
min(map(min, list_of_y_vals)),
max(map(max, list_of_y_vals))
))
if x_label is not None:
plt.xlabel(x_label, fontsize=20)
if y_label is not None:
plt.ylabel(y_label, fontsize=20)
if title is not None:
plt.title(title, fontsize=25)
plt.grid(True)
plt.legend(fontsize=15)
plt.show()
if __name__ == '__main__':
x = np.arange(1, 100)
y = [0.1 * x + 1.0, 0.001 * (x - 50) ** 2, np.log(x)]
colors = ["r", "b", "g"]
labels = ["Linear", "Quadratic", "Log"]
plot_list_of_curves(
[x, x, x],
y,
colors,
labels,
"X-Axis",
"Y-Axis",
"Test Plot"
)