aviss
aviss

Reputation: 2439

"ValueError: RGBA values should be within 0-1 range" after upgrading matplotlib

I have upgraded to matplotlib 3.0.2 and the script below I used to use for my 3d plots throws this error now: ValueError: RGBA values should be within 0-1 range. Tested with the 2.0.2 version and it works there... Tried to google for similar issues but couldn't find a workaround so asking this smart community for help...

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()

Upvotes: 4

Views: 15982

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339200

Your clusters are strings. Prior to matplotlib 2.1 arrays were converted to numbers coincidentally such that the code would run. From matplotlib 2.1 you need to supply numbers in order to have them interpreted as such. E.g.

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

Upvotes: 10

Related Questions