MCPcopy Create free account
hub / github.com/TPCD/DCCL / plot_2D_embedding_mask

Function plot_2D_embedding_mask

project_utils/visualization_utils.py:278–315  ·  view source on GitHub ↗
(save_path, lowDWeights, labels, mask)

Source from the content-addressed store, hash-verified

276
277
278def plot_2D_embedding_mask(save_path, lowDWeights, labels, mask):
279 import matplotlib.pyplot as plt
280 plt.cla()
281 X, Y = lowDWeights[:, 0], lowDWeights[:, 1]
282 unique = np.unique(labels)
283 num_type_color = len(unique)
284 cmap = get_cmap(num_type_color)
285 label2color_dict = {l: i for i, l in enumerate(unique)}
286 c_labels = [label2color_dict[l] for l in labels]
287 # colors = sns.color_palette("viridis", n_colors=num_type_color)
288 colors = sns.color_palette("husl", n_colors=num_type_color)
289
290
291 for x, y, s, m in zip(X, Y, c_labels, mask):
292 if m:
293 plt.text(x, y, ' ', fontsize=1,
294 ha='center', va='center', # 水平居中,垂直居中
295 bbox=dict(alpha=0.5,boxstyle='circle', #
296 ec=colors[s], # 边框颜色
297 fc=colors[s] # 填充颜色
298 ))
299 else:
300
301 plt.text(x, y, ' ', fontsize=1,
302 ha='center', va='center', # 水平居中,垂直居中
303 bbox=dict(alpha=0.5,boxstyle='circle', #
304 ec=colors[s], # 边框颜色
305 fc=colors[s] # 填充颜色
306 ))
307 # plt.xlim(X.min()-padding_rate*X.min(), X.max()+padding_rate*X.max())
308 # plt.ylim(Y.min()-padding_rate*Y.min(), Y.max()+padding_rate*Y.max())
309 plt.xlim(X.min(), X.max())
310 plt.ylim(Y.min(), Y.max())
311 plt.axis('off')
312
313 # plt.title('Visualize Embedding')
314 save_path = save_path + '.png'
315 plt.savefig(save_path, dpi=800)
316
317
318

Callers 1

visualize_gcdFunction · 0.85

Calls 1

get_cmapFunction · 0.85

Tested by

no test coverage detected