Python Forum
read from txt. file in certain manner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read from txt. file in certain manner
#3
Example:
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import csv

x = []
y = []
with open('x_y.txt') as csv_file:
    plots = csv.reader(csv_file, delimiter=',')
    for row in plots:
        x.append(int(row[0]))
        y.append(int(row[1]))

plt.plot(x,y, label='Loaded from file!')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Graph x y')
plt.legend(loc='upper left', shadow=True, fontsize='large')
plt.show()
x_y.txt:
Output:
1,5 2,3 3,4 4,7 5,4
[Image: NRrzlw.jpg]

In future also look into Pandas and Jupyter Notebook.
This can make it easier to load and work with data/plot.
[Image: DoZjfX.jpg]
Reply


Messages In This Thread
RE: read from txt. file in certain manner - by snippsat - Aug-06-2018, 07:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas read csv file in 'date/time' chunks MorganSamage 4 1,806 Feb-13-2023, 11:24 AM
Last Post: MorganSamage
  Can't read text file with pandas zinho 6 12,276 May-24-2020, 06:13 AM
Last Post: azajali43
  Read file Into array with just $0d as Newline lastyle 5 3,467 Feb-03-2020, 11:58 PM
Last Post: lastyle
  Read csv file from Yahoo Finance ian 3 4,762 Sep-22-2019, 06:47 AM
Last Post: ndc85430
  read complex file with both pandas and not Diedro 1 2,974 Jan-29-2019, 05:26 PM
Last Post: Larz60+
  Need help in framing data read from wav file Vishweshkumar 1 3,732 Feb-10-2017, 01:45 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020