Practice 1
import matplotlib.pyplot as plt
import csv
x = []
y = []
with open('example.txt','r') as csvfile:
plots = csv.reader(csvfile,delimiter=',')
for row in plots:
x.append(int(row[0]))
y.append(int(row[1]))
plt.plot(x,y,label='loaded from files')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
plt.show()
Practice 2
import matplotlib.pyplot as plt
import numpy as np
#Part 1
'''
x = []
y = []
with open('example.txt','r') as csvfile:
plots = csv.reader(csvfile,delimiter=',')
for row in plots:
x.append(int(row[0]))
y.append(int(row[1]))
plt.plot(x,y,label='loaded from files')
'''
x,y = np.loadtxt('example.txt',delimiter=',',unpack=True)
plt.plot(x,y,label='loaded from files')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
plt.show()