带有散点图和熊猫的Python seaborn错误

带有散点图和熊猫的Python seaborn错误,python,pandas,matplotlib,seaborn,Python,Pandas,Matplotlib,Seaborn,我试图用Seaborn绘制T-SNE约化向量。我有以下代码: import pandas as pd import numpy as np import seaborn as sns from sklearn.manifold import TSNE import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D tsne = TSNE(n_components=2, verbose=1, perplexity=

我试图用Seaborn绘制T-SNE约化向量。我有以下代码:

import pandas as pd 
import numpy as np
import seaborn as sns
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

tsne = TSNE(n_components=2, verbose=1, perplexity=40, n_iter=300)
tsne_results = tsne.fit_transform(final_data)

df_subset = pd.DataFrame(columns = ['tsne-2d-one', 'tsne-2d-two']) 
df_subset['tsne-2d-one'] = tsne_results[:,0]
df_subset['tsne-2d-two'] = tsne_results[:,1]

plt.figure(figsize=(16,10))

sns.scatterplot(
    x="tsne-2d-one", y="tsne-2d-two",
    hue="y",
    palette=sns.color_palette("hls", 10),
    data=df_subset,
    legend="full")
从上面的代码中可以看到,seaborn lib中的散点图似乎需要Panda.DataFrame输入,所以基本上我以这种方式初始化它为空

df_subset = pd.DataFrame(columns = ['tsne-2d-one', 'tsne-2d-two']) 
然后,我基本上将此数据帧的列分配给每个TSNE维度

df_subset['tsne-2d-one'] = tsne_results[:,0]
df_subset['tsne-2d-two'] = tsne_results[:,1]
我可以毫无问题地打印这些值

然而,当我运行代码时,我得到的是:

File "balance-training.py", line 59, in <module>
    legend="full")
  File "/home/server/.local/lib/python3.6/site-packages/seaborn/relational.py", line 1335, in scatterplot
    alpha=alpha, x_jitter=x_jitter, y_jitter=y_jitter, legend=legend,
  File "/home/server/.local/lib/python3.6/site-packages/seaborn/relational.py", line 852, in __init__
    x, y, hue, size, style, units, data
  File "/home/server/.local/lib/python3.6/site-packages/seaborn/relational.py", line 142, in establish_variables
    raise ValueError(err)
ValueError: Could not interpret input 'y'
文件“balance training.py”,第59行,在
图例=“完整”)
文件“/home/server/.local/lib/python3.6/site packages/seaborn/relational.py”,第1335行,散点图
阿尔法=阿尔法,x_抖动=x_抖动,y_抖动=y_抖动,图例=图例,
文件“/home/server/.local/lib/python3.6/site packages/seaborn/relational.py”,第852行,在__
x、 y、色调、大小、样式、单位、数据
文件“/home/server/.local/lib/python3.6/site packages/seaborn/relational.py”,第142行,在“建立变量”中
提升值错误(err)
ValueError:无法解释输入“y”

我在这里遗漏了什么?

没有列
y
,因此您可以删除
hue=“y”

我认为这里可以将两个向量传递给
x
y
参数,并省略
数据
参数:

sns.scatterplot(
    x=tsne_results[:,0], y=tsne_results[:,1]
    palette=sns.color_palette("hls", 10),
    legend="full")
样本

tsne_results = np.array([[1,2],[4,5],[7,1]])
print (tsne_results)
[[1 2]
 [4 5]
 [7 1]]

sns.scatterplot(
    x=tsne_results[:,0], y=tsne_results[:,1],
    palette=sns.color_palette("hls", 10),
    legend="full")

新手失误:-(谢谢
tsne_results = np.array([[1,2],[4,5],[7,1]])
print (tsne_results)
[[1 2]
 [4 5]
 [7 1]]

sns.scatterplot(
    x=tsne_results[:,0], y=tsne_results[:,1],
    palette=sns.color_palette("hls", 10),
    legend="full")