Spaces:
Running
Running
vickeee465
commited on
Commit
·
433b160
1
Parent(s):
0f6522c
tranpose heatmap
Browse files
app.py
CHANGED
@@ -101,35 +101,39 @@ def prepare_heatmap_data(data):
|
|
101 |
return heatmap_data
|
102 |
|
103 |
def plot_emotion_heatmap(heatmap_data):
|
104 |
-
#
|
|
|
|
|
|
|
105 |
normalized_data = heatmap_data.copy()
|
106 |
-
for row in
|
107 |
-
max_val =
|
108 |
-
normalized_data.loc[row] =
|
109 |
|
110 |
-
#
|
111 |
color_matrix = np.empty((len(normalized_data.index), len(normalized_data.columns), 3))
|
112 |
-
for i,
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
ax.imshow(color_matrix, aspect='auto')
|
122 |
|
123 |
-
#
|
124 |
ax.set_xticks(np.arange(len(normalized_data.columns)))
|
125 |
-
ax.set_xticklabels(normalized_data.columns, rotation=
|
|
|
126 |
ax.set_yticks(np.arange(len(normalized_data.index)))
|
127 |
-
ax.set_yticklabels(normalized_data.index, rotation=0,
|
128 |
|
129 |
-
ax.set_xlabel("
|
130 |
-
ax.set_ylabel("
|
131 |
-
plt.tight_layout()
|
132 |
|
|
|
133 |
return fig
|
134 |
|
135 |
def plot_average_emotion_pie(heatmap_data):
|
|
|
101 |
return heatmap_data
|
102 |
|
103 |
def plot_emotion_heatmap(heatmap_data):
|
104 |
+
# Transpose: now rows = sentences, columns = emotions
|
105 |
+
heatmap_data = heatmap_data.T
|
106 |
+
|
107 |
+
# Normalize each row (sentence-wise)
|
108 |
normalized_data = heatmap_data.copy()
|
109 |
+
for row in normalized_data.index:
|
110 |
+
max_val = normalized_data.loc[row].max()
|
111 |
+
normalized_data.loc[row] = normalized_data.loc[row] / max_val if max_val > 0 else 0
|
112 |
|
113 |
+
# Create color matrix
|
114 |
color_matrix = np.empty((len(normalized_data.index), len(normalized_data.columns), 3))
|
115 |
+
for i, sentence in enumerate(normalized_data.index):
|
116 |
+
for j, emotion in enumerate(normalized_data.columns):
|
117 |
+
val = normalized_data.loc[sentence, emotion]
|
118 |
+
base_rgb = mcolors.to_rgb(emotion_colors[emotion])
|
119 |
+
# Blend from white to base color
|
120 |
+
blended = tuple(1 - val * (1 - c) for c in base_rgb)
|
121 |
+
color_matrix[i, j] = blended
|
122 |
+
|
123 |
+
fig, ax = plt.subplots(figsize=(len(normalized_data.columns) * 0.8 + 2, len(normalized_data.index) * 0.5 + 2))
|
124 |
ax.imshow(color_matrix, aspect='auto')
|
125 |
|
126 |
+
# Set ticks and labels
|
127 |
ax.set_xticks(np.arange(len(normalized_data.columns)))
|
128 |
+
ax.set_xticklabels(normalized_data.columns, rotation=45, ha='right', fontsize=10)
|
129 |
+
|
130 |
ax.set_yticks(np.arange(len(normalized_data.index)))
|
131 |
+
ax.set_yticklabels(normalized_data.index, rotation=0, fontsize=10)
|
132 |
|
133 |
+
ax.set_xlabel("Emotions")
|
134 |
+
ax.set_ylabel("Sentences")
|
|
|
135 |
|
136 |
+
plt.tight_layout()
|
137 |
return fig
|
138 |
|
139 |
def plot_average_emotion_pie(heatmap_data):
|