python中matplotlib绘图时,画布为正方形,但是里面的图不是正方形,该怎么设置
# T-SNE可视化# 取'Conv1D_1'层 的输出为输出新建为model,采用函数模型
Conv1D_1_layer_model = Model(inputs=model.input, outputs=model.get_layer('Conv1D_1').output)
out = Conv1D_1_layer_model.predict(x_train)
print(out.shape)
out = out.reshape(7000, -1)
# np.argmax返回最大数的索引,即可将one-hot编码转换为整数
color =
color = np.stack(color, axis=0)
n_neighbors = 10# 一共有多少个类别
n_components = 2# 降维成几维 2或者3
# 创建自定义图像
fig = plt.figure(figsize=(15,15))# 指定图像的宽和高
# t-SNE的最终结果的降维与可视化
ts = manifold.TSNE(n_components=n_components, init='pca', random_state=0)
y = ts.fit_transform(out)
ax1 = fig.add_subplot(3, 1, 2)
def colormap():
return mpl.colors.LinearSegmentedColormap.from_list \
('cmap', ['#8B0000', '#FF6A6A', '#00FFFF', '#F4A460', '#00CDCD', '#0000FF', '#40E0D0', '#98F5FF', '#FFFF00',
'#FF0000'], 256)
# ('cmap', ['#FFFFFF', '#98F5FF', '#00FF00', '#FFFF00','#FF0000', '#8B0000'], 256) #white, CadetBlue1, Green1, Yellow1, Red,DarkRed
# cm = plt.cm.Spectral
cm = colormap()
plt.scatter(y[:, 0], y[:, 1], c=color, cmap=cm)
ax1.set_title('conv1', fontsize=15)
plt.show()
页:
[1]