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 [ ]:
import os
import gsw
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams

In [ ]:
rcParams['figure.figsize'] = (10, 6)
rcParams['figure.dpi'] = 75
rcParams['lines.linewidth'] = 2
rcParams['axes.facecolor'] = 'white'
rcParams['font.size'] = 14
rcParams['patch.edgecolor'] = 'white'
rcParams['font.family'] = 'StixGeneral'

In [ ]:
def remove_border(axes=None, top=False, right=False, left=True, bottom=True):
    '''Minimize chartjunk by stripping out unnecessary plot borders and axis
    ticks.  The top/right/left/bottom keywords toggle whether the
    corresponding plot border is drawn.'''
    ax = axes or plt.gca()
    ax.spines['top'].set_visible(top)
    ax.spines['right'].set_visible(right)
    ax.spines['left'].set_visible(left)
    ax.spines['bottom'].set_visible(bottom)
    # Turn off all ticks.
    ax.yaxis.set_ticks_position('none')
    ax.xaxis.set_ticks_position('none')
    # Now re-enable visible.
    if top:
        ax.xaxis.tick_top()
    if bottom:
        ax.xaxis.tick_bottom()
    if left:
        ax.yaxis.tick_left()
    if right:
        ax.yaxis.tick_right()

In [ ]:
CT = np.linspace(0, 35, 100)
SA = np.linspace(0, 35, 100)
CT, SA = np.meshgrid(CT, SA)

In [ ]:
sigma_theta = gsw.sigma0_CT_exact(SA, CT)

In [ ]:
levels = np.arange(np.floor(sigma_theta.min()),
                   np.ceil(sigma_theta.max()), 1)
fig, ax = plt.subplots()
cs = ax.contour(SA, CT, sigma_theta, colors='k', levels=levels)
ax.clabel(cs, fmt='%i')
remove_border(ax, top=False, right=False)
ax.set_title(r"$\sigma_{\theta}$")
ax.set_ylabel(r"Temperatura [$^{\circ}$C]")
_ = ax.set_xlabel(r"Salinidade [g kg$^{-1}$]")

In [ ]:
fname = "sigma_theta-full_range.png"
fig.savefig(fname, transparent=True)
_ = os.system('convert -trim %s %s' % (fname, fname))

In [ ]:
HTML(html)