无法使用PYFITS绘制.fit文件

时间:2013-10-06 16:07:40

标签: python pyfits

在Fits文件中,我有三个名为J,H和K的列,我想分别用PYFITS绘制x和y轴上的J-H和H-K之间的关系。 我该怎么做?

1 个答案:

答案 0 :(得分:1)

这是一个非常普遍和基本的问题。

首先你需要打开你的FITS文件和情节,这是一个示例程序:

import pyfits
import matplotlib.pyplot as plt

# Load the FITS file into the program
hdulist = pyfits.open('Your FITS file name here')

# Load table data as tbdata
tbdata = hdulist[1].data

fields = ['J','H','K'] #This contains your column names
var = dict((f, tbdata.field(f)) for f in fields) #Creating a dictionary that contains
                                                 #variable names J,H,K

#Now to call column J,H and K just use
J = var['J']   
H = var['H']
K = var['K']

#To plot J Vs H and H Vs K and so on
plt.plot(J,H,'r')
plt.title('Your plot title here')
plt.show()