I'm slowly replacing all the figures from my class slides with either an open version available online, or a version of my own. So far it has been easier than I thought! Here are one from my Descriptive Oceanography course and another from my Waves and Tides course.
In [2]:
import numpy as np
import seawater as sw
import matplotlib.pyplot as plt
In [3]:
from matplotlib import rcParams
from matplotlib.ticker import MultipleLocator, ScalarFormatter
rcParams['xtick.direction'] = 'out'
rcParams['ytick.direction'] = 'out'
def fix_ticks(ax, x=None, y=None):
ax.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
ax.yaxis.set_major_locator(MultipleLocator(y))
ax.xaxis.set_major_locator(MultipleLocator(x))
In [4]:
S = np.linspace(0, 35.5, 50)
T = np.linspace(0, 20, 50)
P = np.linspace(0, 5000, 50)
Tfreeze = np.linspace(0, -2.0, 50)
In [5]:
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(6, 6))
ax0, ax1, ax2, ax3 = axes.ravel()
fig.subplots_adjust(left=0.15, wspace=0.5, hspace=0.5)
ax0.plot(T, sw.dens(35, T, 0))
ax0.set_title('S=35.0, p=0')
ax0.set_xlabel(u'Temperatura [\u00b0C]')
ax0.set_ylabel(r'Densidade [kg m$^{-3}$]')
fix_ticks(ax0, x=4, y=1)
ax1.plot(P, sw.dens(35, 0, P))
ax1.set_title(u'S=35.0, T=0')
ax1.set_xlabel(u'Pressão [dbar]')
ax1.set_ylabel(r'Densidade [kg m$^{-3}$]')
fix_ticks(ax1, x=2000, y=5)
ax2.plot(T, sw.dens(0, T, 0))
ax2.set_title(u'S=0, p=0')
ax2.set_xlabel(u'Temperatura [\u00b0C]')
ax2.set_ylabel(r'Densidade [kg m$^{-3}$]')
fix_ticks(ax2, x=4, y=0.2)
ax3.plot(S, Tfreeze)
ax3.set_title(u'Ponto de congelamento')
ax3.set_ylabel(u'Temperatura [\u00b0C]')
ax3.set_xlabel(r'Salinidade [g kg$^{-1}$]')
fix_ticks(ax3, x=10, y=0.2)
In [6]:
twopi = 2 * np.pi
n = 2
A = 2
w = twopi / 10
k = twopi / 200
phi = np.deg2rad(180)
t = np.arange(0, 10 * n, 0.01)
y = A * np.cos(w * t - k * 0 + phi)
In [7]:
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='->', color='black'))
_ = ax.annotate(u'Espaço', xy=(20, 0), xycoords='data',
xytext=(20, 0.05), textcoords='data',
va='bottom', ha='right', color='blue')
_ = ax.annotate('Tempo', xy=(20, 0), xycoords='data',
xytext=(20, -0.05), textcoords='data',
va='top', ha='right', color='red')
# Arrow commom properties.
arrowprops = dict(arrowstyle='<->', color='black')
# Wave period (or length).
_ = ax.annotate('', xy=(15, 2.5), xycoords='data',
xytext=(5, 2.5), textcoords='data',
arrowprops=arrowprops)
_ = ax.annotate(u'Comprimento', xy=(10, 2.5), xycoords='data',
xytext=(10, 2.55), textcoords='data',
va='bottom', ha='center', color='blue')
_ = ax.annotate(u'Período', xy=(10, 2.5), xycoords='data',
xytext=(10, 2.45), textcoords='data',
va='top', ha='center', color='red')
# Amplitude.
_ = ax.annotate('', xy=(5, 2), xycoords='data',
xytext=(5, 0), textcoords='data',
arrowprops=arrowprops)
_ = ax.annotate('Amplitude', xy=(5, 1), xycoords='data',
xytext=(4.9, 1), textcoords='data',
va='center', ha='right', rotation=90)
# Height.
ax.annotate('', xy=(15, 2), xycoords='data',
xytext=(15, -2), textcoords='data',
arrowprops=arrowprops)
_ = ax.annotate('Altura', xy=(15, 1), xycoords='data',
xytext=(14.9, 0.1), textcoords='data',
va='bottom', ha='right', rotation=90)
# Angle.
_ = ax.annotate('', xy=(15, 2), xycoords='data',
xytext=(5, -2), textcoords='data',
arrowprops=arrowprops)
_ = ax.annotate(u'Inclinação', xy=(10, 0), xycoords='data',
xytext=(10.5, 0.5), textcoords='data',
va='center', ha='center', rotation=35)
In [8]:
HTML(html)
Out[8]: