Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,16 +53,32 @@ def _matrix_payload(np_mat: np.ndarray, labels: Optional[List[str]] = None):
|
|
| 53 |
|
| 54 |
def _plot_heatmap(D: np.ndarray, labels: Optional[List[str]] = None) -> np.ndarray:
|
| 55 |
"""Return an RGB image (as numpy array) of the heatmap."""
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
im = ax.imshow(D, cmap="viridis")
|
| 58 |
-
plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
|
|
|
|
|
|
|
| 59 |
if labels and len(labels) == D.shape[0]:
|
| 60 |
ax.set_xticks(np.arange(len(labels)))
|
| 61 |
ax.set_yticks(np.arange(len(labels)))
|
| 62 |
-
ax.set_xticklabels(labels, rotation=60, ha="right", fontsize=8)
|
| 63 |
-
ax.set_yticklabels(labels, fontsize=8)
|
| 64 |
-
|
|
|
|
| 65 |
ax.grid(False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
fig.tight_layout()
|
| 67 |
|
| 68 |
# Render and grab RGBA buffer (works across Matplotlib versions)
|
|
|
|
| 53 |
|
| 54 |
def _plot_heatmap(D: np.ndarray, labels: Optional[List[str]] = None) -> np.ndarray:
|
| 55 |
"""Return an RGB image (as numpy array) of the heatmap."""
|
| 56 |
+
# Set dark mode style
|
| 57 |
+
plt.style.use('dark_background')
|
| 58 |
+
|
| 59 |
+
fig, ax = plt.subplots(figsize=(6, 5), dpi=160, facecolor='#1e1e1e')
|
| 60 |
+
ax.set_facecolor('#1e1e1e')
|
| 61 |
+
|
| 62 |
im = ax.imshow(D, cmap="viridis")
|
| 63 |
+
cbar = plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
|
| 64 |
+
cbar.ax.tick_params(colors='white') # Light colorbar labels
|
| 65 |
+
|
| 66 |
if labels and len(labels) == D.shape[0]:
|
| 67 |
ax.set_xticks(np.arange(len(labels)))
|
| 68 |
ax.set_yticks(np.arange(len(labels)))
|
| 69 |
+
ax.set_xticklabels(labels, rotation=60, ha="right", fontsize=8, color='white')
|
| 70 |
+
ax.set_yticklabels(labels, fontsize=8, color='white')
|
| 71 |
+
|
| 72 |
+
ax.set_title("Dataset Distance Matrix", color='white')
|
| 73 |
ax.grid(False)
|
| 74 |
+
|
| 75 |
+
# Set axis colors to light
|
| 76 |
+
ax.spines['bottom'].set_color('white')
|
| 77 |
+
ax.spines['top'].set_color('white')
|
| 78 |
+
ax.spines['right'].set_color('white')
|
| 79 |
+
ax.spines['left'].set_color('white')
|
| 80 |
+
ax.tick_params(colors='white', which='both')
|
| 81 |
+
|
| 82 |
fig.tight_layout()
|
| 83 |
|
| 84 |
# Render and grab RGBA buffer (works across Matplotlib versions)
|