gpt4 book ai didi

python-3.x - "ValueError: RGBA values should be within 0-1 range"升级 matplotlib 后

转载 作者:行者123 更新时间:2023-12-03 23:36:28 25 4
gpt4 key购买 nike

我已经升级到 matplotlib 3.0.2,我以前用于 3d 绘图的下面的脚本现在抛出这个错误:ValueError: RGBA values should be within 0-1 range .使用 2.0.2 版本进行了测试,它在那里工作......试图用谷歌搜索类似的问题,但找不到解决方法,所以向这个聪明的社区寻求帮助......

test = pd.DataFrame({'cluster': ["0", "1", "2"],
'x': [2, 3, 1],
'y': [10, 5, -2],
'z': [-10, -5, 2]})

fig = plt.figure(figsize=(7,7))

ax = Axes3D(fig)

x=test['x']
y=test['y']
z=test['z']
clusters = test['cluster']

ax.scatter(x, y, z, c=clusters, marker='x', cmap='tab20b', depthshade=False)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

最佳答案

你的集群是字符串。在 matplotlib 2.1 之前,数组被巧合地转换为数字,以便代码可以运行。从 matplotlib 2.1 开始,您需要提供数字以便将它们解释为这样。例如。

clusters = test['cluster'].astype(int)

关于python-3.x - "ValueError: RGBA values should be within 0-1 range"升级 matplotlib 后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53749579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com