In [1]:
# Graphing helper function
def setup_graph(title='', x_label='', y_label='', fig_size=None):
fig = plt.figure()
if fig_size != None:
fig.set_size_inches(fig_size[0], fig_size[1])
ax = fig.add_subplot(111)
ax.set_title(title)
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
In [2]:
# Generate some complex numbers, and convert them to (x,y) coordinates
complex_points = [e**(1j * i) for i in linspace(0, 2*pi, 16)]
real_parts = [z.real for z in complex_points]
imag_parts = [z.imag for z in complex_points]
# Matplotlib code to draw graph
fig = plt.figure()
fig.set_size_inches(6, 6)
ax = fig.add_subplot(111)
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
ax.set_xlim((-1.5,1.5))
ax.set_xticks(linspace(-1.5,1.5,4))
ax.set_ylim((-1.5,1.5))
ax.set_yticks(linspace(-1.5,1.5,4))
ax.annotate("{0} + {1}i".format(real_parts[1], imag_parts[1]), xy=(real_parts[1], \
imag_parts[1]), xytext=(1,1), arrowprops=dict(facecolor='black', shrink=0.08))
_ = plot(real_parts, imag_parts, 'go')
In [3]:
t = linspace(0, 3 * 2*pi, 100)
e_func = [e**(1j * i) for i in t]
In [4]:
setup_graph(title='real part (cosine) of e^ix', x_label='time', y_label='amplitude of real part', fig_size=(12,6))
_ = plot(t, [i.real for i in e_func])
In [5]:
setup_graph(title='imaginary part (sin) of e^ix', x_label='time', y_label='amplitude of imaginary part', fig_size=(12,6))
_ = plot(t, [i.imag for i in e_func])
In [5]: