In [ ]:
from IPython.core.display import HTML
with open('../../common/creativecommons.html', 'r') as f:
html = f.read()
with open('../../common/custom.css', 'r') as f:
styles = f.read()
HTML(styles)
text = 'Check this post at'
uri = 'http://nbviewer.ipython.org/urls/raw.github.com/ocefpaf/python4oceanographers/master/content/downloads/notebooks'
name = get_notebook_name()
link = """<p>%s <a href="%s/%s"><em>nbviewer</em>.</a></p>""" % (text, uri, name)
html += str(link)
In [ ]:
twopi = 2 * np.pi
n = 2 # Duas ondas.
A = 2 # Amplitude = 2 metros.
w = twopi / 10 # T = 10 segundos.
k = twopi / 200 # lambda = 200 metros.
phi = np.deg2rad(180) # Fase [rad]
t = np.arange(0, 10 * n, 0.01) # Vetor tempo [s]
y = A * np.cos(w * t - k * 0 + phi) # Um ponto do oceano.
In [ ]:
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(t, y, linewidth='2', color='#006633')
ax.set_frame_on(False)
ax.axis([-0.1, 20.1, -3, 3])
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
# Box.
kw = dict(linestyle='--', color='grey', zorder=90)
ax.axhline(y=2, xmin=0.15, xmax=0.85, **kw)
ax.axhline(y=-2, xmin=0.15, xmax=0.85, **kw)
ax.axvline(x=5, ymin=-0.15, ymax=1.85, **kw)
ax.axvline(x=15, ymin=-0.15, ymax=1.85, **kw)
# Zero line.
_ = ax.annotate('', xy=(20, 0), xycoords='data',
xytext=(0, 0), textcoords='data',
arrowprops=dict(arrowstyle='->', facecolor='black'))
_ = ax.annotate(u'Espaço (x)', xy=(20, 0), xycoords='data',
xytext=(20, 0.05), textcoords='data',
va='bottom', ha='right', color='blue')
_ = ax.annotate('Tempo (t)', xy=(20, 0), xycoords='data',
xytext=(20, -0.05), textcoords='data',
va='top', ha='right', color='red')
# Arrow commom properties.
arrowprops = dict(arrowstyle='<->', facecolor='black')
# Wave period (or length).
_ = ax.annotate('', xy=(15, 2.5), xycoords='data',
xytext=(5, 2.5), textcoords='data',
arrowprops=arrowprops)
_ = ax.annotate(r'$\lambda$', xy=(10, 2.5), xycoords='data',
xytext=(10, 2.55), textcoords='data',
va='bottom', ha='center')
# Amplitude.
_ = ax.annotate('', xy=(5, 2), xycoords='data',
xytext=(5, 0), textcoords='data',
arrowprops=arrowprops)
_ = ax.annotate('a', xy=(5, 1), xycoords='data',
xytext=(4.9, 1), textcoords='data',
va='center', ha='right', rotation=0)
# Height.
ax.annotate('', xy=(15, 2), xycoords='data',
xytext=(15, -2), textcoords='data',
arrowprops=arrowprops)
_ = ax.annotate('h', xy=(15, 1), xycoords='data',
xytext=(14.9, 0.1), textcoords='data',
va='bottom', ha='right', rotation=0)
# Angle.
_ = ax.annotate('', xy=(15, 2), xycoords='data',
xytext=(5, -2), textcoords='data',
arrowprops=arrowprops)
_ = ax.annotate(r'$\alpha$', xy=(10, 0), xycoords='data',
xytext=(10.5, 0.5), textcoords='data',
va='center', ha='center', rotation=35)
In [ ]:
fig.savefig('wave_definitions.pdf')
In [ ]:
HTML(html)