vickeee465 commited on
Commit
433b160
·
1 Parent(s): 0f6522c

tranpose heatmap

Browse files
Files changed (1) hide show
  1. app.py +24 -20
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
- # Normalize values to [0, 1] per row (emotion)
 
 
 
105
  normalized_data = heatmap_data.copy()
106
- for row in heatmap_data.index:
107
- max_val = heatmap_data.loc[row].max()
108
- normalized_data.loc[row] = heatmap_data.loc[row] / max_val if max_val > 0 else 0
109
 
110
- # Build custom RGB color matrix
111
  color_matrix = np.empty((len(normalized_data.index), len(normalized_data.columns), 3))
112
- for i, emotion in enumerate(normalized_data.index):
113
- base_rgb = mcolors.to_rgb(emotion_colors[emotion])
114
- for j, val in enumerate(normalized_data.loc[emotion]):
115
- # Linear interpolation from white to base color
116
- color = tuple(1 - val * (1 - c) for c in base_rgb)
117
- color_matrix[i, j] = color
118
-
119
- fig, ax = plt.subplots(figsize=(len(normalized_data.columns) * 0.5 + 4, len(normalized_data.index) * 0.5 + 2))
120
-
121
  ax.imshow(color_matrix, aspect='auto')
122
 
123
- # Ticks and labels
124
  ax.set_xticks(np.arange(len(normalized_data.columns)))
125
- ax.set_xticklabels(normalized_data.columns, rotation=0, ha='center')
 
126
  ax.set_yticks(np.arange(len(normalized_data.index)))
127
- ax.set_yticklabels(normalized_data.index, rotation=0, ha='right')
128
 
129
- ax.set_xlabel("Sentences")
130
- ax.set_ylabel("Emotions")
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):