0

I'm trying to access a .fits file and plotting two columns (out of many!). I used pyfits to access the file, and

plt.plotfile('3XMM_DR5.fits', delimiter=' ', cols=(0, 1), names=('x-axis','y-axis'))

but that's not working. Are there any alternatives? And is there any way to open the file using python? In order to access the data table

Iguananaut
  • 15,675
  • 4
  • 43
  • 50
Diana
  • 1
  • 1

1 Answers1

0

According to the docs from matplotlib for plotfile:

Note: plotfile is intended as a convenience for quickly plotting data from flat files; it is not intended as an alternative interface to general plotting with pyplot or matplotlib.

This isn't very clear. I think by "flat files" it just means CSV data or something--this function isn't used very much in my experience, and it certainly does't know anything about FITS files, which are seldom used outside astronomy. You mentioned in your post that you did something with PyFITS, but that isn't demonstrated anywhere in your question.

PyFITS, incidentally, has been deprecated for several years now, and its functionality is integrated into Astropy.

You can open a table from a FITS file with astropy.Table.read:

from astropy.table import Table
table = Table.read('3XMM_DR5.fits')

then access the columns with square bracket notation like:

plt.plot(table['whatever the x axis column is named'], table['y axis column name'])
Iguananaut
  • 15,675
  • 4
  • 43
  • 50