0

Usually scatter plots use one x value, one y value. The point is colored using a z value. My scatter plot requirement is different. I have a list of x points, list of y points to be plotted using a z value or one color. My code:

 samdf = pd.DataFrame({'x':[[1,2,3],4,5,6],
                     'y':[[10,20,30],40,50,60],
                     'z':[7,8,9,10]})
 plt.scatter(samdf['x'],samdf['y'],c=samdf['z'],cmap='jet')
 plt.colorbar()
 plt.show()

Present output:

ValueError: setting an array element with a sequence.

1 Answer 1

1

Sorry I don't have the reputation to comment.

The problem isn't caused by matplotplib but rather the dictionary you defined when initializing the dataframe.

You have defined your DataFrame as

samdf = pd.DataFrame({'x':[[1,2,3],4,5,6],
                     'y':[[10,20,30],40,50,60],
                     'z':[7,8,9,10]})

This is impossible each row in each column should be of a primitive type. This is equivalent to the following table:

x       | y          | z 
-------------------------
[1,2,3] | [10,20,30] | 7
-------------------------
4       | 40         | 8
5       | 50         | 9
...

which is not a valid table.

What is that dictionary even trying to achieve?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.