-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutility.py
More file actions
38 lines (27 loc) · 733 Bytes
/
utility.py
File metadata and controls
38 lines (27 loc) · 733 Bytes
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
import matplotlib.pyplot as plt
from torch import Tensor
def str2int(s: str, default: int = 0) -> int:
try:
return int(s)
except:
return default
def str2float(s: str, default: float = 0.0) -> float:
try:
return float(s)
except:
return default
def clear_patch(ax: plt.Axes, gid: str) -> None:
# print(ax.patches)
for c in ax.patches:
if c.get_gid() == gid:
c.remove()
break
def clear_line(ax: plt.Axes, gid: str) -> None:
for l in ax.lines:
if l.get_gid() == gid:
l.remove()
break
def clear_collection(ax:plt.Axes, gid: str) -> None:
for c in ax.collections:
if c.get_gid() == gid:
c.remove()