How to create a 2D graph from data in a file using matplotlib in Python?

4 hours ago 4
ARTICLE AD BOX

I am working on a Python project and I need to generate a 2D graph using matplotlib.

The data is stored in a text file with two columns (x and y values).

Example file:

1 10

2 20

3 30

4 40

How can I read the data from the file and plot it using matplotlib?

My attempt:

import matplotlib.pyplot as plt

# read file here

plt.plot(x,y)

plt.show()

Read Entire Article