In [51]:
%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
In [52]:
from IPython.html.widgets import interact, interactive, fixed
from IPython.display import display
In [53]:
from math import pi
Write a plot_sin1(a, b) function that plots $sin(ax+b)$ over the interval $[0,4\pi]$.
$3\pi$.
In [54]:
def plot_sin1(a, b):
x = np.linspace(0, 4 * pi, 100)
plt.plot(x, np.sin((c *x) + d))
plt.xlim(0, 4 * pi)
plt.ylim(-1.0, 1.0)
plt.box(False)
In [63]:
plot_sin1(5, 3.4)
Then use interact to create a user interface for exploring your function:
a should be a floating point slider over the interval $[0.0,5.0]$ with steps of $0.1$.b should be a floating point slider over the interval $[-5.0,5.0]$ with steps of $0.1$.
In [56]:
v = interact(plot_sine1, a=(0.0,5.0,0.1), b=(-5.0,5.0,0.1));
v
In [57]:
assert True # leave this for grading the plot_sine1 exercise
In matplotlib, the line style and color can be set with a third argument to plot. Examples of this argument:
r--bok.Write a plot_sine2(a, b, style) function that has a third style argument that allows you to set the line style of the plot. The style should default to a blue line.
In [67]:
# YOUR CODE HERE
def plot_sin2 (a, b, style):
x = np.linspace(0, 4 * pi, 100)
plt.plot(x, np.sin((c *x) + d))
plt.xlim(0, 4 * pi)
plt.ylim(-1.0, 1.0)
plt.box(False)
In [69]:
plot_sin2(4.0, -1.0, 'b--')
Use interact to create a UI for plot_sine2.
a and b as above.
In [77]:
q = interact(plot_sin2, a=(0.0,5.0,0.1), b=(-5.0,5.0,0.1), style={'blue dots': 'b.', 'black circles': 'ko', 'red triangles': 'r^'});
q
In [75]:
assert True # leave this for grading the plot_sine2 exercise
In [ ]: