Skip to content

Instantly share code, notes, and snippets.

@stephenmm
Last active August 29, 2015 13:57
Show Gist options
  • Save stephenmm/9520787 to your computer and use it in GitHub Desktop.
Save stephenmm/9520787 to your computer and use it in GitHub Desktop.
Interactively play with data in matplotlib!!!
# Interactively play with data in matplotlib!!!
# Start python command line:
# > python
# >>>
# Then copy and paste the code below.
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
# Initialize matplotlib to be interactive
mpl.rcParams['backend'] = 'TkAgg'
mpl.rcParams['interactive'] = 'True'
def pcnt_change( v ):
for a, b in zip(v[::1], v[1::1]):
return str( 100 * (b - a) / float(a) ) + " val: "+ str(b)
def compund_return( principal, rate, years ):
amnts = []
for year in range( 1, years+1 ):
amnts.append( principal * ( 1.0 + rate ) ** year )
return amnts
vals = [794,895,935,980,1002,1017,1028,1080,1072,1122,1109,1157]
plt.plot(vals)
plt.show()
vals = [938, 1157, 1272, 1399, 1539, 1693, 1863, 2049, 2254, 2480, 2728, 3000, 3301, 3631, 3994, 4393, 4833]
plt.plot(vals)
sum(vals)
np.mean(vals)
chng = pcnt_change(vals)
print chng
plt.plot(chng)
amounts = compund_return( vals[-1], .10, 15 )
print "Year %21s" % "Amount on deposit"
for year, amnt in enumerate(amounts):
print "%4d%21.2f" % ( year, amnt )
plt.plot(amounts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment