Matplotlib で Contour を描く (例題; コンプトン散乱の反跳電子)
contour を描いてみた覚え書き。式は以下ね。
contour は numpy の meshgrid として以下が参考になります。
http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html
import numpy import pylab def electron_energy(gamma, theta): numerator = gamma**2*(1-numpy.cos(theta)) denominator = 1 + gamma * (1-numpy.cos(theta)) electron_energy = numerator / denominator # in a unit of m_ec^2 return electron_energy fig = pylab.plt.figure() gamma_min = 0 gamma_max = 1.9 gamma_del = 0.1 theta_min = 0 theta_max = 180 theta_del = 1 x = numpy.arange(gamma_min, gamma_max, gamma_del) y = numpy.arange(theta_min, theta_max, theta_del) xx, yy = numpy.meshgrid(x,y) zz = electron_energy(xx, numpy.radians(yy)) print zz cont = pylab.plt.contour(xx, yy, zz) pylab.clabel(cont, inline=2, fontsize=13) pylab.grid(True) pylab.title("Recoil Electron Energy $E_e$ ($m_ec^2$)", fontsize=12, fontname='serif') pylab.xlabel("Normalized Input Photon Energy ($m_ec^2$)", fontsize=12, fontname='serif') pylab.ylabel("Scater Angle of the Photon ($\degree$)", fontsize=12, fontname='serif') fig.savefig("compton_electron_energy_contour.png", format='png')