Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to draw scatter plot using Matplotlib

📅 2015-Jun-23 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

[caption id="attachment_7021" align="aligncenter" width="578"][Scatter plot drawn using Matplotlib](https://codeyarns.files.wordpress.com/2015/06/20150623_scatter.png) Scatter plot drawn using Matplotlib[/caption]

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