-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_utils.py
96 lines (72 loc) · 2.46 KB
/
plot_utils.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
from svgpathtools import svg2paths, wsvg
import re
import numpy as np
import glob
import os
import pandas as pd
def plot_heatmap(data,
ylabel,
xlabel,
minimization=False,
savefig_path=None,
):
plt.clf()
plt.cla()
ser = pd.Series(list(data.values()),
index=pd.MultiIndex.from_tuples(data.keys()))
df = ser.unstack().fillna(0)
df = ser.unstack().fillna(np.inf)
# figure
fig, ax = plt.subplots(figsize=(8, 8))
cmap = sns.cubehelix_palette(as_cmap=True)
# Set the color for the under the limit to be white (0.0) so empty cells are not visualized
# cmap.set_under('-1.0')
# Plot NaN in white
cmap.set_bad(color='white')
ax = sns.heatmap(df)
ax.invert_yaxis()
plt.xlabel(xlabel)
plt.ylabel(ylabel)
# get figure to save to file
if savefig_path:
ht_figure = ax.get_figure()
fig_name = savefig_path+"/heatmap_"+xlabel+"_"+ylabel
print(os.path.abspath(fig_name))
ht_figure.savefig(fig_name)
plt.clf()
plt.cla()
plt.close()
def plot_svg(xml, filename):
root = ET.fromstring(xml)
svg_path = root.find(NAMESPACE + 'path').get('d')
wsvg(svg_path, filename=filename+'.svg')
def getImage(path):
return OffsetImage(plt.imread(path))
def plot_fives(dir_path, xlabel, ylabel):
paths = glob.glob(dir_path + "/"+xlabel+"_"+ylabel+"/*.png")
x=[]
y=[]
for a in paths:
pattern = re.compile('([\d\.]+),([\d\.]+)')
segments = pattern.findall(a)
for se in segments:
x.append(int(se[0]))
y.append(int(se[1]))
plt.cla()
fig, ax = plt.subplots(figsize=(10,10))
#ax.scatter(x, y)
for x0, y0, path in zip(x, y,paths):
ab = AnnotationBbox(getImage(path), (y0, x0), frameon=False)
ax.add_artist(ab)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.xticks(np.arange(-1, 25, 1))
plt.yticks(np.arange(-1, 25,1))
plt.grid(color='blue', linestyle='-', linewidth=0.09)
ht_figure = ax.get_figure()
ht_figure.savefig(dir_path+"/fives_"+xlabel+"_"+ylabel, dpi=400)
plt.clf()
plt.close()