【发布时间】:2019-01-10 12:47:31
【问题描述】:
我只是想绘制 x、y,然后用簇给它们上色。每个集群都应该有唯一的颜色。但我收到错误。我尝试不使用 numpy 数组,但仍然出现错误。
" 形状为 (5113,) 的 c 不能作为 x 大小为 5113、y 大小为 5113"" 的颜色序列
x = np.array(df['ip_indexed'])
print(x.shape)
y = np.array(df['geohash_indexed'])
print(y.shape)
labels = np.array(df['clusters'])
print(labels.shape)
''' output.
(5113,)
(5113,)
(5113,)
'''
LABEL_COLOR_MAP = {9066 : 'r',
9068: 'silver',
17182 : 'k',
17183: 'c',
17184: 'indigo',
17185: 'tan',
17186: 'plum',
17187: 'yello',
17188:'olive',
17189:'deeppink'
}
label_color = np.array([LABEL_COLOR_MAP[l] for l in labels])
label_color.shape
plt.figure(figsize=(50, 10))
plt.xlabel("ip_address", fontsize= 20)
plt.ylabel("geohash", fontsize= 20)
plt.title("clusters", fontsize= 50)
colors = np.random.rand(5113)
plt.scatter(x, y , c = label_color)
ValueError: c of shape (5113,) not acceptable as a color sequence for x with size 5113, y with size 5113
【问题讨论】:
-
你能分享一个数据点少的例子吗,比如说
x和y,大小为3? -
"yello"不是有效颜色。 Appart没有理由会失败。你能提供一个minimal reproducible example,即一个可以重现的可运行代码吗? -
x= [414 414 414 ... 420 421 422] y=[ 0 0 2 ... 210 211 212]
-
标签 = [ 9066 9066 9068 ... 17187 17188 17189]
-
yello 不是问题。我纠正了它,仍然是同样的问题。
标签: python matplotlib scatter-plot