In [ ]:
import astropy.units as u
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
plt.style.use('apw-notebook')
%matplotlib inline

In [ ]:
def ln_dv_pdf(x, sigma):
    return 2*np.log(x) - x**2/(4*sigma**2) - 1.2655121234846456 - 3*np.log(sigma)

def comoving_ln_pdf(x, sigma):
    """ Normal distribution truncated at 0 (x >= 0) """
    x = np.abs(x)
    return -0.5*(x/sigma)**2 - 0.22579135264472741 - np.log(sigma)

In [ ]:
fig,ax = plt.subplots(1, 1, figsize=(5,5))

v = np.linspace(0, 100, 1024)

p_field = np.exp(ln_dv_pdf(v, 18.))
ax.plot(v, p_field / p_field.max(), 
        marker='', linewidth=2, label=r'$p_{\rm field}(\psi)$')
ax.text(57, 0.6, r'$\sigma_{\rm field} \approx 18\,{\rm km}\,{\rm s}^{-1}$',
        fontsize=12)

p_co = np.exp(comoving_ln_pdf(v, 1.))
ax.text(2, 0.95, r'$\sigma_{\rm co} = 1\,{\rm km}\,{\rm s}^{-1}$',
        fontsize=12)
ax.plot(v, p_co / p_co.max(), marker='', 
        linestyle='--', linewidth=2, label=r'$p_{\rm co}(\psi)$')

ax.set_xlim(0, 100)
ax.set_xlabel(r'$\psi$ [{0:latex_inline}]'.format(u.km/u.s))

ax.legend(loc='upper right', fontsize=16)
fig.savefig('mixture-model-demo.pdf')

In [ ]: