In [2]:
from ipywidgets import *
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display
%matplotlib inline
In [24]:
phase = widgets.IntSlider()
display(phase)
i = 0
xdata = []
ydata = []
fig = plt.figure()
ax = fig.add_subplot(111)
line1, = ax.plot(xdata, ydata, 'b-') # Returns a tuple of line objects, thus the comma
plt.ylim(0,200)
plt.xlim(0,100)
def on_value_change(change):
global i
i += 1
phaseval = change['new']
a1 = 0.5
a2 = 0.5
a3 = (np.exp(1j*phaseval)*a1 + 1j*a2)/np.sqrt(2)
a4 = (1j*np.exp(1j*phaseval)*a1 + a2)/np.sqrt(2)
xdata.append(i)
ydata.append(a4)
line1.set_ydata(ydata)
line1.set_xdata(xdata)
print(xdata)
phase.observe(on_value_change, names='value')
In [10]:
a1 = 0.5
a2 = 0.5
a3 = (np.exp(1j*phaseval)*a1 + 1j*a2)/np.sqrt(2)
a4 = (1j*np.exp(1j*phaseval)*a1 + a2)/np.sqrt(2)
In [ ]:
In [32]:
xdata = []
ydata = []
y2data = []
for i in range(50):
phaseval = i*np.pi/10
a1 = 0.5
a2 = 0.5
a3 = (np.exp(1j*phaseval)*a1 + 1j*a2)/np.sqrt(2)
a4 = (1j*np.exp(1j*phaseval)*a1 + a2)/np.sqrt(2)
xdata.append(phaseval)
ydata.append(a3*a3.conjugate())
y2data.append(a4*a4.conjugate())
fig = plt.figure()
ax = fig.add_subplot(111)
line1, = ax.plot(xdata, ydata, 'b-') # Returns a tuple of line objects, thus the comma
line2, = ax.plot(xdata, y2data, 'b-') # Returns a tuple of line objects, thus the comma
In [ ]: