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.

foobarbaz
  • 508
  • 1
  • 10
  • 27

1 Answers1

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()
Mr. T
  • 11,960
  • 10
  • 32
  • 54