import matplotlib.pyplot as plt # the pound sign indicates a comment import numpy as np from pylab import * import os #some font crap -- ignore font = {'family' : 'serif', 'weight' : 'normal', 'size' : 14} plt.rc('font', **font) plt.rc('text', usetex=False) #don't try to understand what is plt or figure or axis object, just accept it plt.figure(figsize=(7,4)) #width and heigh ot figure fig = plt.figure(1) ax = fig.add_axes([0.1,0.15,0.85,0.76]) # (offset of yaxis,xaxis,width,height as % of window) #read in some data mydata = np.loadtxt('sample_plot.dat',skiprows=1) #first line of this file was comment mydata = mydata.transpose() # if data for given variable is in given column (rather than by row) # mydata is a matrix of values, now t,x,y are the 0th, 4th and 5th column t=mydata[0] x=mydata[4] y=mydata[5] plt.plot(t,x,linestyle='-',linewidth=3,color='g',markersize=8, marker='s', markerfacecolor='none', markeredgecolor='g',markeredgewidth=2) plt.plot(t,y,linestyle='--',linewidth=3,color='r',markersize=8, marker='o', markerfacecolor='r', markeredgecolor='r',markeredgewidth=2) #plt.semilogy(x,y) #if in future you want log plot, you would need this command ax.tick_params(axis='both', which='major', labelsize=14) ax.set_xticks(np.arange(0,30,5), minor=False) ax.set_xticklabels(np.arange(0,30,5), minor=False, family='serif') ax.set_xticks(np.arange(0,30,1), minor=True) plt.xlim(0,24) ax.set_yticks(np.arange(-12,12,3), minor=False) ax.set_yticklabels(np.arange(-12,12,3), minor=False, family='serif') ax.set_yticks(np.arange(-12,12,1), minor=True) plt.ylim(-11,11) plt.xlabel('$t$ (s)', fontsize=18, weight='normal') plt.ylabel('$x,y$ (cm)',fontsize=18) plt.title('Dopey plot, some greeks: $\\alpha,\\beta,\\gamma$', fontsize=16, color='gray') plt.savefig('sample_plot.pdf',format='pdf') plt.show() #os.system("open -a Preview sample_plot.pdf") #For OSX, this can replace "show" quit()