Plot List of X,y Coordinates in Matplotlib

Suppose we have a list of 2-tuple like (x, y), and we need to plot them as they are the (x, y) coordinates.

data = [
    [1, 2],
    [3, 2],
    [4, 7],
    [2, 4],
    [2, 1],
    [5, 6],
    [6, 3],
    [7, 5],
]

Complete codes to plot this list of (x, y) coordinates in Matplotlib,

import matplotlib.pyplot as plt

data = [
    [1, 2],
    [3, 2],
    [4, 7],
    [2, 4],
    [2, 1],
    [5, 6],
    [6, 3],
    [7, 5],
]

x, y = zip(*data)
plt.scatter(x, y)
plt.show()

Matplotlib Scatter Plot list of coordinate

x, y = zip(*data)

It unpacks the data from pairs to lists by using zip function.

plt.scatter(x, y)

We need to create the scatter plot, therefore scatter is the right plot type to be used in this application.

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Matplotlib Scatter Plot

  • Plot Points in Matplotlib