1

I have a matrix A:

    A = np.matrix(np.random.rand(4,2))


    matrix([[ 0.01124212,  0.45879116],
            [ 0.10993219,  0.00142847],
            [ 0.34650295,  0.98693131],
            [ 0.20417694,  0.81177707]])

Is there an easy way to use matplotlib (or similar libary) to show a scatterplot in 2-d? When I use plt.plot(A) it shows as a line graph.

1
  • 2
    The linked answer seems long when you can just do this: plt.scatter(*A.T) Commented Feb 18, 2018 at 18:55

1 Answer 1

2

Just define rows in your numpy array as x, y pairs:

from matplotlib import pyplot as plt
A = np.matrix(np.random.rand(4,2))

#scatter plot x - column 0, y - column 1, shown with marker o
plt.plot(A[:, 0], A[:, 1], 'o', label = 'data')
#create legend in case you have more than one series
plt.legend()
plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.