pythonmatplotlibastropyfits

Plot a FITS image with changed axes


I wanted to plot this image in fits format.

But I get this instead

I've tried to change the axes with imshow but it doesn't do anything better. This is the code that i'm using.

import matplotlib.pyplot as plt
from astropy.visualization import astropy_mpl_style
plt.style.use(astropy_mpl_style)
from astropy.utils.data import get_pkg_data_filename
from astropy.io import fits

image_file = get_pkg_data_filename('Or.fits')
fits.info(image_file)
image_data = fits.getdata(image_file, ext=0)
print(image_data.shape)

plt.figure()
plt.imshow(image_data, cmap='gray')
plt.colorbar()

Solution

  • From the second image that you posted in your question, it seems that image_data has super large values with most the data points being very small. Try mapping data points logarithmically to hopefully solve the problem.

    Add the below to the beginning of your code:

    from matplotlib.colors import LogNorm
    

    And change your plotting line to the following so that matplotlib uses the logarithm of those values when plotting your image.

    plt.imshow(image_data, cmap='gray', norm=LogNorm())