SDSS Line-ratio Diagrams

This shows how to plot line-ratio diagrams for the SDSS spectra. These diagrams are often called BPT plots 1, Osterbrock diagrams 2, or Kewley diagrams 3. The location of the dividing line is taken from from Kewley et al 2001.



Baldwin, J. A.; Phillips, M. M.; Terlevich, R. (1981)…93….5B


Osterbrock, D. E.; De Robertis, M. M. (1985)…97.1129O


Kewley, L. J. et al. (2001)…556..121K


# Author: Jake VanderPlas <>
# License: BSD
#   The figure is an example from astroML: see
import numpy as np
from matplotlib import pyplot as plt

from astroML.datasets import fetch_sdss_corrected_spectra
from import log_OIII_Hb_NII

data = fetch_sdss_corrected_spectra()

i = np.where((data['lineindex_cln'] == 4) | (data['lineindex_cln'] == 5))

plt.scatter(data['log_NII_Ha'][i], data['log_OIII_Hb'][i],
            c=data['lineindex_cln'][i], s=9, lw=0)

NII = np.linspace(-2.0, 0.35)
plt.plot(NII, log_OIII_Hb_NII(NII), '-k')
plt.plot(NII, log_OIII_Hb_NII(NII, 0.1), '--k')
plt.plot(NII, log_OIII_Hb_NII(NII, -0.1), '--k')
plt.xlim(-2.0, 1.0)
plt.ylim(-1.2, 1.5)

plt.xlabel(r'$\mathrm{log([NII]/H\alpha)}$', fontsize='large')
plt.ylabel(r'$\mathrm{log([OIII]/H\beta)}$', fontsize='large')