Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to draw scatter plot using Matplotlib

📅 2015-Jun-23 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ color, marker, matplotlib, scatter ⬩ 📚 Archive

Scatter plot drawn using Matplotlib
Scatter plot drawn using Matplotlib

Scatter plots are useful to show data points that lie in 2D. Drawing a scatter plot in Matplotlib is easy using the scatter function.

import matplotlib.pyplot as mplot

# x_vals is NumPy array of shape (N, 1)
# y_vals is NumPy array of shape (N, 1)
mplot.scatter(x_vals, y_vals)
import matplotlib.pyplot as mplot

# x_vals is NumPy array of shape (N, 1)
# y_vals is NumPy array of shape (N, 1)
# c_arr  is NumPy array of shape (N, 3)

mplot.scatter(x_vals, y_vals, s=2, marker=".", facecolors=c_arr, edgecolors="none", alpha=0.5)

Tried with: Matplotlib 1.3.1 and Ubuntu 14.04