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

Function plot_2D_embedding

project_utils/visualization_utils.py:245–274  ·  view source on GitHub ↗
(save_path, lowDWeights, labels)

Source from the content-addressed store, hash-verified

243
244
245def plot_2D_embedding(save_path, lowDWeights, labels):
246 import matplotlib.pyplot as plt
247 padding_rate = 0.1
248 plt.cla()
249 X, Y = lowDWeights[:, 0], lowDWeights[:, 1]
250 unique = np.unique(labels)
251 num_type_color = len(unique)
252 cmap = get_cmap(num_type_color)
253 label2color_dict = {l: cmap(i) for i, l in enumerate(unique)}
254 colors = sns.color_palette("viridis", n_colors=num_type_color)
255
256 for x, y, s in zip(X, Y, labels):
257 plt.text(x, y, s, fontsize=1,
258 ha='center', va='center', # 水平居中,垂直居中
259 bbox=dict(boxstyle='square', #
260 ec=colors[s], # 边框颜色
261 fc=colors[s] # 填充颜色
262 ))
263 # plt.xlim(X.min()-padding_rate*X.min(), X.max()+padding_rate*X.max())
264 # plt.ylim(Y.min()-padding_rate*Y.min(), Y.max()+padding_rate*Y.max())
265 plt.xlim(X.min(), X.max())
266 plt.ylim(Y.min(), Y.max())
267 plt.axis('off')
268
269 # plt.title('Visualize Embedding')
270 save_path = save_path + '.png'
271 plt.savefig(save_path, dpi=800)
272 plt.show()
273
274 plt.pause(0.01)
275
276
277

Callers 4

visualizeFunction · 0.85
visualize_gcdFunction · 0.85
visualize2Function · 0.85
visualize3Function · 0.85

Calls 1

get_cmapFunction · 0.85

Tested by

no test coverage detected