In [1]:
%matplotlib inline
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 = 'rho_STP'
link = """<p>%s <a href="%s/%s"><em>nbviewer</em>.</a></p>""" % (text, uri, name)
html += str(link)
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)
In [5]:
fig = plt.figure(figsize=(8, 8))
ax0 = fig.add_axes([0.1, 0.6, 0.35, 0.35])
ax1 = fig.add_axes([0.6, 0.6, 0.35, 0.35])
ax2 = fig.add_axes([0.35, 0.1, 0.35, 0.35])
ax0.plot(S, sw.dens(S, 0, 0))
ax0.set_title(u'T=0, p=0')
ax0.set_xlabel(r'Salinidade [g kg$^{-1}$]')
ax0.set_ylabel(r'Densidade [kg m$^{-3}$]')
fix_ticks(ax0, x=10, y=10)
ax1.plot(T, sw.dens(35, T, 0))
ax1.set_title('S=35.0, p=0')
ax1.set_xlabel(u'Temperatura [\u00b0C]')
ax1.set_ylabel(r'Densidade [kg m$^{-3}$]')
fix_ticks(ax1, x=4, y=1)
ax2.plot(P, sw.dens(35, 0, P))
ax2.set_title(u'S=35.0, T=0')
ax2.set_xlabel(u'Pressão [dbar]')
ax2.set_ylabel(r'Densidade [kg m$^{-3}$]')
fix_ticks(ax2, x=2000, y=5)
In [6]:
fig.savefig('densidade.pdf')
In [7]:
HTML(html)
Out[7]: