-latex code in matplotlib
天体物理科研作图要求
plot_example.py
import astropy.io.fits as pyfits
from pylab import *
import pylab
fig_width_pt = 255.76535 # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27 # Convert pt to inches
golden_mean = 1.2*(sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt # width in inches
fig_height = fig_width*golden_mean # height in inches
fig_size = [fig_width,fig_height]
params = {'axes.labelsize': 10,
'font.size': 10,
'legend.fontsize': 8,
'xtick.labelsize': 8,
'ytick.labelsize': 8,
'text.usetex': True,
# 'backend':'pdf',
'figure.figsize': fig_size,
"patch.linewidth": 0.5,
"lines.linewidth":0.5,
"axes.linewidth":0.1}
pylab.rcParams.update(params)
pylab.rc('font',**{'family':'serif','serif':['Times']})
plot([1,2,3]) #Here should be changed.
xlabel('Energy, keV') #Here should be changed.
ylabel(r'keV$^2$(Photons cm$^{-2}$s$^{-1}$keV$^{-1}$)') #Here should be changed.
subplots_adjust(left=0.15,right=0.97,top=0.97,bottom=0.15)
savefig('example.pdf')
astropy.io.fits 提供对FITS文件的访问权限。
FITS (Flexible Image Transport System)是广泛用于天文界的存储图标的便携文件标准。
关于坐标,用matplotlib里的latex code,例如r" L x , 1 0 35 L_x, 10^{35} Lx,1035,erg,s − 1 ^{-1} −1"
r"$L_x, 10^{35}$\,erg\,s$^{-1}$
- r"XX" syntax tells matplotlib to take the string literally and pass it to latex, might be needed if you use Tex for rendering.