In [11]:
import matplotlib.pyplot as plt
%matplotlib inline
In [12]:
fig = plt.figure()
ax = fig.add_subplot(2,1,1) # two rows, one column, first plot
import numpy as np
t = np.arange(0.0, 1.0, 0.01)
s = np.sin(2*np.pi*t)
line, = ax.plot(t, s, color='blue', lw=2)
In [13]:
ax.lines[0]
Out[13]:
In [14]:
fig
Out[14]:
In [15]:
line
Out[15]:
In [16]:
ax.lines.remove(line)
In [17]:
fig
Out[17]:
In [20]:
ax.lines.append(line)
In [21]:
fig
Out[21]:
In [22]:
xtext = ax.set_xlabel('my xdata') # returns a Text instance
ytext = ax.set_ylabel('my ydata')
In [23]:
fig
Out[23]:
In [24]:
plt.plot([1,2,3])
Out[24]:
In [25]:
plt.subplot(211)
Out[25]:
In [26]:
plt.plot(range(12))
Out[26]:
In [27]:
plt.subplot(212, axisbg='y') # creates 2nd subplot with yellow background
Out[27]:
In [28]:
# plot a line, implicitly creating a subplot(111)
plt.plot([1,2,3])
# now create a subplot which represents the top plot of a grid
# with 2 rows and 1 column. Since this subplot will overlap the
# first, the plot (and its axes) previously created, will be removed
plt.subplot(211)
plt.plot(range(12))
plt.subplot(212, axisbg='y') # creates 2nd subplot with yellow background
Out[28]:
In [29]:
import matplotlib.pyplot as plt
import numpy as np
dt = 0.01
Fs = 1/dt
t = np.arange(0, 10, dt)
nse = np.random.randn(len(t))
r = np.exp(-t/0.05)
cnse = np.convolve(nse, r)*dt
cnse = cnse[:len(t)]
s = 0.1*np.sin(2*np.pi*t) + cnse
plt.subplot(3, 2, 1)
plt.plot(t, s)
plt.subplot(3, 2, 3)
plt.magnitude_spectrum(s, Fs=Fs)
plt.subplot(3, 2, 4)
plt.magnitude_spectrum(s, Fs=Fs, scale='dB')
plt.subplot(3, 2, 5)
plt.angle_spectrum(s, Fs=Fs)
plt.subplot(3, 2, 6)
plt.phase_spectrum(s, Fs=Fs)
plt.show()
In [ ]: