-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_helper.py
48 lines (42 loc) · 1.08 KB
/
plot_helper.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
import matplotlib.pyplot as plt
import numpy as np
def safe_name(unsafe: str):
unsafe = unsafe.replace(" ", "-")
def repl(c: str):
if c.isalnum() or c in ('.', '_', '!', '$'):
return c
else:
return "-"
return "".join(map(repl, list(unsafe)))
def plot(
x_label: str,
y_label: str,
x_vals: np.array,
y_vals: np.array,
):
NAME = f"{x_label}/{y_label}"
plt.figure(num=NAME)
plt.plot(x_vals, y_vals)
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.title(NAME)
plt.savefig(f"{safe_name(NAME)}.svg", bbox_inches='tight')
plt.show()
def plot_3d(
x_label: str,
y_label: str,
z_label: str,
x_vals: np.array,
y_vals: np.array,
z_vals: np.array,
):
NAME = f"({x_label}, {y_label}) :-> {z_label}"
fig = plt.figure(num=NAME)
fig.suptitle(NAME)
ax = fig.add_subplot(projection='3d')
ax.scatter(x_vals, y_vals, z_vals)
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
ax.set_zlabel(z_label)
plt.savefig(f"{safe_name(NAME)}.svg", bbox_inches='tight')
plt.show()