ValueError: c argument has n elements, which is not acceptable for use with x with size 0, y with size 0

ValueError: c argument has n elements, which is not acceptable for use with x with size 0, y with size 0

我正在尝试使用 matplotlib/seaborn:

绘制散点图
plt.figure(figsize=(16,10))
sns.scatterplot(
    x=[i[0] for i in tsne_data],
    y=[i[1] for i in tsne_data],
    alpha=0.3,
    color=label_colors
)

我遇到错误:

ValueError: 'c' argument has 267794 elements, which is not acceptable for use with 'x' with size 0, 'y' with size 0.

我的数据:

我不明白为什么我会收到这个错误,尤其是为什么 'x' 和 'y' 没有被识别为有任何长度。我尝试使用 pandas 数据框来代替,我有一个 'x' 和 'y' 列,然后设置 x=df['x']x=list(df['x']) 但我得到了同样的错误.我如何绘制我的 tsne_data 以便它的 267,794 个点中的每个点都用 label_colors 中相应索引处指定的颜色着色?

根据 seaborn documentation 你应该使用参数 hue 例如:

plt.figure(figsize=(16,10))
sns.scatterplot(
    x=[i[0] for i in tsne_data],
    y=[i[1] for i in tsne_data],
    alpha=0.3,
    hue=label_colors
)