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.
我的数据:
label_colors
— 一个包含 267,794 个元素的 Python 列表。每个元素都是一个字符串,例如'red', 'blue', 'purple'.
tsne_data
— 具有 267,794 个元素的 Numpy 二维数组。每个元素都是一个 x, y 坐标,例如[ 9.417695 , -25.48891 ]
。形状为 (267794, 2)。
我不明白为什么我会收到这个错误,尤其是为什么 '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
)
我正在尝试使用 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.
我的数据:
label_colors
— 一个包含 267,794 个元素的 Python 列表。每个元素都是一个字符串,例如'red', 'blue', 'purple'.tsne_data
— 具有 267,794 个元素的 Numpy 二维数组。每个元素都是一个 x, y 坐标,例如[ 9.417695 , -25.48891 ]
。形状为 (267794, 2)。
我不明白为什么我会收到这个错误,尤其是为什么 '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
)