Plot from txt file after writing it using input

51 Views Asked by At

I am trying to plot a graph using coordinates from a txt file. What I would like to do is to update this file everyday, adding a line at the end. On this line there are the coordinate for the line I want to plot. The first coordinate is the date of current day, the second one is a value a should add using the INPUT function in python (the program should ask me for that).

Unfortunately I keep having a EOFError.

I don't know how to fix it.

import numpy as np
import matplotlib.pyplot as plt
from datetime import date

oggi = date.today()
oggi1 = oggi.strftime("%d%m%Y")

f = open("/storage/emulated/0/Python/lista.txt", "a")

dato = int(input("Value: "))
f.write("\n" + oggi1 + " - " + dato)

f.close()

with open("/storage/emulated/0/Python/lista.txt") as f:
    lines = f.readlines()
    x = [line.split()[0] for line in lines]
    y = [line.split()[1] for line in lines]
    
fig = plt.figure()

ax1 = fig.add_subplot(111)

ax1.set_title("Plot title")    
ax1.set_xlabel('x label')
ax1.set_ylabel('y label')

ax1.plot(x,y, c='r', label='the data')

leg = ax1.legend()

plt.show()
0

There are 0 best solutions below