Boom
Boom

Reputation: 1325

How to draw scatter plot of np.array?

Assume I have the following array:

X = np.array([[1, 2], [2, 2], [2, 3], [8, 7], [8, 8], [25, 80]])

How can I make scatter plot (matplotlib) of X ?

scatter require 2 parameters (x, y)

Upvotes: 2

Views: 6286

Answers (2)

user3668129
user3668129

Reputation: 4840

import matplotlib.pyplot as plt
plt.scatter(*zip(*X))
plt.show()

Upvotes: 1

Joe Todd
Joe Todd

Reputation: 897

import numpy as np
import matplotlib.pyplot as plt


X = np.array([[1, 2], [2, 2], [2, 3], [8, 7], [8, 8], [25, 80]])

plt.scatter(X[:,0], X[:,1])
plt.show()

Upvotes: 7

Related Questions