-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathplot_utils.py
123 lines (93 loc) · 2.99 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import matplotlib.pyplot as plt
import seaborn as sns
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_heatmap_rescaled(data,
ylabel,
xlabel,
min_value_y=0,
max_value_y=25,
min_value_x=0,
max_value_x=25,
minimization=False,
savefig_path=None,
):
plt.clf()
plt.cla()
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.name)
plt.ylabel(ylabel.name)
num_cells_x = 25
num_cells_y = 25
# if max_value_x > 25:
# num_cells_x = 25
# else:
# num_cells_x = max_value_x + 1
# if max_value_y > 25:
# num_cells_y = 25
# else:
# num_cells_y = max_value_y + 1
xtickslabel = [round(the_bin, 1) for the_bin in np.linspace(min_value_x, max_value_x, num_cells_x)]
ytickslabel = [round(the_bin, 1) for the_bin in np.linspace(min_value_y, max_value_y, num_cells_y)]
ax.set_xticklabels(xtickslabel)
plt.xticks(rotation=45)
ax.set_yticklabels(ytickslabel)
plt.yticks(rotation=0)
# get figure to save to file
if savefig_path:
ht_figure = ax.get_figure()
fig_name = savefig_path+"/heatmap_"+xlabel.name+"_"+ylabel.name
print(os.path.abspath(fig_name))
ht_figure.savefig(fig_name)
plt.clf()
plt.cla()
plt.close()