Created
September 27, 2012 14:15
-
-
Save tsbertalan/3794246 to your computer and use it in GitHub Desktop.
Make graphs from the output of APC 524's HW1. Be sure to suitable edit the filename and authorname variables near the top.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import matplotlib.pyplot as plt | |
def import_text(filename, separator): | |
for line in csv.reader(open(filename), delimiter=separator, skipinitialspace=True): | |
if line: | |
yield line | |
results = [] | |
t = [] | |
x = [] | |
y = [] | |
eulername = 'outfile_euler.txt' | |
abname = 'outfile_ab.txt' | |
rkname = 'outfile_rk.txt' | |
authorname = 'Tom' | |
for data in import_text(eulername, ' '): | |
t.append(float(data[0])) | |
x.append(float(data[1])) | |
y.append(float(data[2])) | |
results.append((t,x,y,"Euler")) | |
t = [] | |
x = [] | |
y = [] | |
for data in import_text(abname, ' '): | |
t.append(float(data[0])) | |
x.append(float(data[1])) | |
y.append(float(data[2])) | |
results.append((t,x,y,"Adams-Bashforth")) | |
t = [] | |
x = [] | |
y = [] | |
for data in import_text(rkname, ' '): | |
t.append(float(data[0])) | |
x.append(float(data[1])) | |
y.append(float(data[2])) | |
results.append((t,x,y,"Runge-Kutta")) | |
fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(11, 8.5), sharex=True) | |
axes = axes.flat | |
fig.suptitle(authorname) | |
plots = [] | |
for i, (t, x, y, name) in enumerate(results): | |
axes[i].plot(t,x,t,y) | |
axes[i].set_title(name) | |
# axes[i].set_xlim([0,xmax]) | |
axes[i].set_ylabel('x or y=dx/dt') | |
plt.setp(axes[i].get_xticklabels(), visible=False) | |
h, l = axes[i].get_legend_handles_labels() | |
# print h | |
axes[i].legend(['x','y=dx/dt']) | |
axes[-1].set_xlabel('t') | |
plt.setp(axes[-1].get_xticklabels(), visible=True) | |
#fig.tight_layout() | |
plt.savefig('duffing_'+authorname+'.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment