In [1]:
import matplotlib.pyplot as plt
import numpy as np
import math
In [2]:
x = np.linspace(-2, 2, 500)
y = x**2
plt.title("Square function")
plt.xlabel("x")
plt.ylabel("y = x**2")
plt.plot(x, y,'g--') # specify styles using g-- green dashed lines
plt.show()
Check out this website for more styles to control https://matplotlib.org/2.0.2/api/pyplot_api.html
In [3]:
x = np.linspace(-2, 2, 500)
y = x**3
plt.xlabel("x")
plt.ylabel("y")
plt.title(" y=x^3")
plt.plot(x, y)
plt.show()
In [4]:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-2, 2, 500)
dashes = [10, 5, 100, 5] # 10 points on, 5 off, 100 on, 5 off
fig, ax = plt.subplots()
line1, = ax.plot(x, np.sin(x), '--', linewidth=2,
label='Dashes set retroactively')
line1.set_dashes(dashes)
line2, = ax.plot(x, -1 * np.sin(x), dashes=[30, 5, 10, 5],
label='Dashes set proactively')
ax.legend(loc='lower right')
plt.show()
In [5]:
x = np.linspace(-2, 2, 500)
fig, ax = plt.subplots()
line1, = ax.plot(x, x**2, linewidth=3)
line2, = ax.plot(x, x-2,'g-')
plt.show()
In [6]:
pi=math.pi
math.cos(2*pi)
math.exp(1.0)
Out[6]:
2.718281828459045
In [7]:
import math
tau=4.0
f0=5.0
t = np.linspace(0, 10, 2000)
y=np.exp(-16*((t-tau)/tau)**2)*np.cos(2*pi*f0*t)
#here y is a pulse, electric field pulse as a function of time, the pulse occurs at tau=4.0ns; the pulse has a frequency 5.0Ghz
#
#y= np.exp(-t)
plt.xlabel("x (ns)")
plt.ylabel("y")
plt.plot(t, y)
plt.show()
In [ ]: