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

from matplotlib import style
style.use('dark_background')

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]:
fig.savefig('densidade.pdf')

In [7]:
HTML(html)


Out[7]:

"Aulas de Oceanografia Física Descritiva" by Filipe Fernandes is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Based on a work at http://ocefpaf.github.io/.

Check this post at nbviewer.