# Plotting columns of data from a file import pandas as pd import numpy as np import matplotlib.pyplot as plt df = pd.read_csv('spring_midpoint.dat',sep='\s+',names=['t','y','vy','E']) plt.plot(df.t,df.y,label='y(t)') plt.plot(df.t,df.vy,label='v(t)') plt.plot(df.t,df.E,label='E(t)') # label axes plt.xlabel('t (s)') plt.ylabel('y (m), $v_y$ (m/s) or E (J)') # axes scales #plt.xlim(0,10) #plt.ylim(-5,5) plt.legend() # save the plot as an image plt.savefig('midpoint.pdf') #plt.savefig('midpoint.eps',format='eps') #plt.show()