In [2]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

1. Simple plots

In [3]:
xs = np.linspace(0,4,100)
#(a)
plt.plot(xs, np.sin(xs)**2, 'r-')
plt.plot(xs, np.sin(xs**2), 'b-');
In [4]:
#(b)
plt.rcParams.update({'font.size': 14})
plt.xlabel('x')
plt.ylabel('y')
plt.title("Some simple plots")
#(c)
plt.plot(xs, np.sin(xs)**2, 'g-', linewidth=3, label="$\sin(x)^2$")
plt.plot(xs, np.sin(xs**2), 'm-', linewidth=3, label="$\sin(x^2)$")
plt.legend();  #(d)
plt.savefig("test.png"); #(e)

2. Multiple plots: Lissajous curves

In [5]:
ts = np.linspace(0,30,600) 
fig, axes = plt.subplots(2,2)
fig.set_size_inches(8,6)
axs = axes.flatten()
bs = [1,2,3,np.pi]
a = 1.0; A=1; B=1; d=np.pi/2
for i in range(4):
    axs[i].axis('equal')
    axs[i].plot(A*np.sin(a*ts+d), B*np.sin(bs[i]*ts), 'r-', linewidth=1)

3. Elliptic curves

In [6]:
avals = [1, 0, -1, -2]
xs = np.linspace(-3,3,600)
fig, axes = plt.subplots(2,2)
fig.set_size_inches(8,6)
axs = axes.flatten()
for i in range(4):
    axs[i].axis('equal')
    axs[i].plot(xs, np.sqrt(xs**3+avals[i]*xs+1), 'r-')
    axs[i].plot(xs, -np.sqrt(xs**3+avals[i]*xs+1), 'r-') 
    axs[i].set_xlim(-3,3)
    axs[i].set_ylim(-3,3)
 
/Users/samdolan/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:8: RuntimeWarning: invalid value encountered in sqrt
  
/Users/samdolan/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:9: RuntimeWarning: invalid value encountered in sqrt
  if __name__ == '__main__':

4. Coin flipping

In [8]:
def heads(N=10):
    return sum(np.random.randint(0,2,N))
data = np.array([heads() for i in range(1024)])
plt.hist(data, bins=11, range=(0,11));
# Approximately, the bin counts are in proportion to the N=10th row of Pascal's triange.
In [ ]: